Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Schopp/fix async #378

Merged
merged 18 commits into from
Oct 31, 2023
Merged
Show file tree
Hide file tree
Changes from 11 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ env:
on:
release:
types: [created]
pull_request:
branches:
- master

jobs:
build:
Expand All @@ -20,6 +23,7 @@ jobs:
- run: npm test

publish-npm:
if: startsWith(github.ref, 'refs/tags/v')
needs: build
runs-on: ubuntu-latest
steps:
Expand All @@ -29,6 +33,7 @@ jobs:
node-version: ${{ env.NODE_VERSION }}
registry-url: https://registry.npmjs.org/
- run: npm ci
- run: npm version ${{ env.RELEASE_VERSION }}
- run: npm run build
- run: npm publish
env:
Expand Down
2 changes: 1 addition & 1 deletion examples/balls/client/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* Jet client-server communications:
*/
import { select, selectAll, pointer } from 'd3-selection'
import { Fetcher, Peer } from '../../../src'
import { Fetcher, Peer } from '../../../lib'
import { canvasSize } from '../defs'
import { ballType } from '../server'

Expand Down
2 changes: 1 addition & 1 deletion examples/balls/server/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env node

import { Daemon, Method, Peer, State } from '../../../src'
import { Daemon, Method, Peer, State } from '../../../lib'
import { canvasSize } from '../defs'

var port = parseInt(process.argv[2]) || 8081
Expand Down
16 changes: 14 additions & 2 deletions examples/chat/client/index.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
/*
* Jet client-server communications:
*/
import { Fetcher, Peer } from '../../../src'
import { Peer } from '../../../lib/3_jet/peer/index.js'
import { Fetcher } from '../../../lib/3_jet/peer/fetcher.js'
import './base.css'
import { LogLevel } from '../../../lib/jet.js'

const peer = new Peer({ url: 'ws://localhost:8081/' })
const peer = new Peer({
url: 'ws://localhost:8081/',
log: { logName: '', logCallbacks: [console.log], logLevel: LogLevel.socket }
})

const renderMessages = (messages: { value: string[] }) => {
const messageContainer = document.getElementById('messages')!
Expand All @@ -26,6 +31,13 @@ document
.getElementById('message-form')!
.addEventListener('submit', function (event) {
event.preventDefault()
// const ps = [
Florian-Schopp marked this conversation as resolved.
Show resolved Hide resolved
// new Promise((res,rej)=>{peer.set("test1",5).then(res).catch(rej)}),
// new Promise((res,rej)=>{peer.set("test2",15).then(res).catch(rej)})
// ]
// Promise.allSettled(ps).then((res)=>{
// console.log(res)
// })
const messageInput = document.getElementById('message')! as HTMLInputElement
const sendButton = document.getElementById('send')! as HTMLButtonElement
const message = messageInput.value
Expand Down
16 changes: 10 additions & 6 deletions examples/chat/server/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env node

import { Daemon, Method, Peer, State } from '../../../src'
import { Daemon, LogLevel, Method, Peer, State } from '../../../lib/jet.js'

const wsPort = parseInt(process.argv[2]) || 8081
const internalPort = 10222
Expand All @@ -21,7 +21,8 @@ console.log('listening on port', wsPort)

// Create Jet Peer
const peer = new Peer({
port: internalPort
port: internalPort,
log: { logName: '', logCallbacks: [console.log], logLevel: LogLevel.socket }
})

// the messages state is simply an array
Expand All @@ -44,10 +45,13 @@ const clear = new Method('chat/clear')
clear.on('call', () => {
messages.value([])
})

peer
.connect()
.then(() =>
Promise.all([peer.add(messages), peer.add(append), peer.add(clear)])
)
.then(() => {
peer.batch(() => {
peer.add(messages)
peer.add(append)
peer.add(clear)
})
})
.then(() => {})
2 changes: 1 addition & 1 deletion examples/chat/webpack.config.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -73,4 +73,4 @@ const clientConfig = {
]
}

module.exports = [clientConfig, serverConfig]
module.exports = [serverConfig,clientConfig]
2 changes: 1 addition & 1 deletion examples/todo/client/client.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* Jet client-server communications:
*/
import { Fetcher, Peer, PublishMessage, ValueType } from '../../../src'
import { Fetcher, Peer, PublishMessage, ValueType } from '../../../lib'
import { Todo } from '../server/Todo'
import './base.css'

Expand Down
2 changes: 1 addition & 1 deletion examples/todo/server/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Daemon, Method, Peer, State, ValueType } from '../../../src'
import { Daemon, Method, Peer, State, ValueType } from '../../../lib'
import { Todo } from './Todo'

var port = parseInt(process.argv[2]) || 8081
Expand Down
72 changes: 36 additions & 36 deletions examples/todo/webpack.config.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -38,40 +38,40 @@ const serverConfig = {
level: 'log' // enables logging required for problem matchers
}
}
const clientConfig = {
target: 'web',
mode: 'none',
context: path.resolve('./', 'examples', 'todo', 'client'),
entry: './client.ts',
output: {
path: path.resolve('./', 'examples', 'todo', 'dist'),
filename: 'client.js',
publicPath: '/',
clean: true
},
module: {
rules: [
{
test: /\.ts$/,
use: ['ts-loader']
},
{
test: /\.(scss|css)$/,
use: ['style-loader', 'css-loader', 'postcss-loader']
}
]
},
resolve: {
extensions: ['.ts', '.js'],
alias: { events: require.resolve('events/') }
},
devtool: 'nosources-source-map',
plugins: [
new HtmlWebpackPlugin({
title: 'TODO',
template: 'index.html'
})
]
}
// const clientConfig = {
// target: 'web',
// mode: 'none',
// context: path.resolve('./', 'examples', 'todo', 'client'),
// entry: './client.ts',
// output: {
// path: path.resolve('./', 'examples', 'todo', 'dist'),
// filename: 'client.js',
// publicPath: '/',
// clean: true
// },
// module: {
// rules: [
// {
// test: /\.ts$/,
// use: ['ts-loader']
// },
// {
// test: /\.(scss|css)$/,
// use: ['style-loader', 'css-loader', 'postcss-loader']
// }
// ]
// },
// resolve: {
// extensions: ['.ts', '.js'],
// alias: { events: require.resolve('events/') }
// },
// devtool: 'nosources-source-map',
// plugins: [
// new HtmlWebpackPlugin({
// title: 'TODO',
// template: 'index.html'
// })
// ]
// }

module.exports = [clientConfig, serverConfig]
module.exports = [serverConfig]
12 changes: 6 additions & 6 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 6 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,16 +34,17 @@
],
"scripts": {
"test": "jest",
"prepare": "npm version patch",
"build": "tsc",
"ci": "npm run ci:eslint && npm run ci:prettier && npm run ci:type-check && npm run test",
"ci:eslint": "eslint --max-warnings 0 --ignore-path .prettierignore $npm_package_config_files",
"ci:prettier": "prettier --check $npm_package_config_files ",
"ci:type-check": "tsc --noEmit --skipLibCheck",
"prettier": "prettier --write $npm_package_config_files",
"eslint": "eslint --max-warnings 0 --ignore-path .prettierignore $npm_package_config_files",
"ex:chat": "concurrently \"webpack serve --config examples/chat/webpack.config.cjs\" \"wait-on examples/chat/dist/server.cjs && node examples/chat/dist/server.cjs\"",
"ex:todo": "concurrently \"webpack serve --config examples/todo/webpack.config.cjs\" \"wait-on examples/todo/dist/server.cjs && node examples/todo/dist/server.cjs\"",
"ex:balls": "concurrently \"webpack serve --config examples/balls/webpack.config.cjs\" \"wait-on examples/balls/dist/server.cjs && node examples/balls/dist/server.cjs\""
"eslint": "eslint --fix --max-warnings 0 --ignore-path .prettierignore $npm_package_config_files",
"ex:chat": "npm run build && concurrently \"webpack serve --config examples/chat/webpack.config.cjs\" \"wait-on examples/chat/dist/server.cjs && node examples/chat/dist/server.cjs\"",
"ex:todo": "npm run build && concurrently \"webpack serve --config examples/todo/webpack.config.cjs\" \"wait-on examples/todo/dist/server.cjs && node examples/todo/dist/server.cjs\"",
"ex:balls": "npm run build && concurrently \"webpack serve --config examples/balls/webpack.config.cjs\" \"wait-on examples/balls/dist/server.cjs && node examples/balls/dist/server.cjs\""
},
"dependencies": {
"css-loader": "^6.8.1",
Expand Down Expand Up @@ -77,7 +78,7 @@
"typescript": "^5.2.2",
"wait-for-expect": "^3.0.2",
"wait-on": "^7.0.1",
"webpack": "^5.88.2",
"webpack": "^5.89.0",
"webpack-cli": "^5.1.4",
"webpack-dev-server": "^4.15.1"
},
Expand Down
Loading