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/fixed fetch #379

Merged
merged 8 commits into from
Nov 3, 2023
Merged
Show file tree
Hide file tree
Changes from all 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
11 changes: 5 additions & 6 deletions examples/todo/client/client.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
/*
* Jet client-server communications:
*/
import { Fetcher, Peer, PublishMessage, ValueType } from '../../../lib'
import { Fetcher, Peer, PublishMessage } from '../../../lib'
import { Todo } from '../server/Todo'
import './base.css'

const todoList: Record<string, Todo> = {}
const peer = new Peer({ url: `ws://localhost:8081/` })
const peer = new Peer({
url: `ws://localhost:8081/`
})

const addTodo = (title: string) => {
peer.call('todo/add', [title])
peer.call('todo/add', [title]).catch(() => console.log('Failed to add'))
}

const removeTodo = (id: string) => {
Expand Down Expand Up @@ -127,9 +129,6 @@ document.getElementById('todo-form')!.addEventListener('submit', (event) => {
peer
.connect()
.then(() => peer.authenticate('Admin', 'test'))
.then(() => peer.get({ path: { startsWith: 'test' } }))
.then((val) => console.log(val))
// .then(() => peer.authenticate('Operator', ''))
.then(() => peer.fetch(todos))
.then(() => renderTodos())
.catch((ex) => console.log(ex))
11 changes: 6 additions & 5 deletions examples/todo/server/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,6 @@ console.log('listening on port', port)
var peer = new Peer({
url: `ws://localhost:8081/`
})
// const peer2 = new jet.Peer({
// port: internalPort,log:{logCallbacks:[console.log],logname:"Peer 2",loglevel:jet.LogLevel.debug}

// })

var todoStates: Record<string, State<Todo>> = {}

Expand All @@ -46,8 +42,13 @@ addTodo.on('call', (args) => {
todoState.on('set', (requestedTodo) => {
todo.merge(requestedTodo)
})
if (todo.id in todoStates) {
throw 'already existent'
}
todoStates[todo.id] = todoState
peer.add(todoState)
peer.add(todoState).catch(() => {
console.log('State already existent')
})
})

// Provide a "todo/remove" method to delete a certain todo
Expand Down
Loading