UNPKG

@logux/client

Version:

Logux base components to build web client

25 lines (23 loc) 654 B
import { Client } from '../client/index.js' import { LoguxUndoError } from '../logux-undo-error/index.js' export function request(action, opts) { if (!opts.userId) opts.userId = 'anonymous' let client = new Client(opts) return new Promise((resolve, reject) => { client.node.catch(e => { client.destroy() reject(e) }) client.on('add', response => { if (response === action) return client.destroy() if (response.type === 'logux/undo') { reject(new LoguxUndoError(response)) } else { resolve(response) } }) client.log.add(action, { sync: true }) client.start() }) }