Skip to content

Commit

Permalink
Schopp/fixed fetch (#379)
Browse files Browse the repository at this point in the history
* Fixed async fetching

* Fixed tests

* Fixed examples

* Deleted filelogger

* Fixed forwarding

* Updated packages

* Fixed error call

* Fixed
  • Loading branch information
Florian-Schopp authored Nov 3, 2023
1 parent 8a71aab commit 0c63657
Show file tree
Hide file tree
Showing 13 changed files with 1,079 additions and 961 deletions.
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

0 comments on commit 0c63657

Please sign in to comment.