Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const onError =
params.onError ||
(err => {
throw err;
});
const window = params.window || globalWindow;
const debugConfig: DebugConfig = {
failingWrites: false,
pretendOffline: false,
optimisticUIEnabled: true
};
const canonData = initialData;
const events = new NanoEvents>();
const { connectivity, observe, push } = sync({
canonData,
network,
onChange: (kind, id) => events.emit("change", [kind, id]),
onConnectivityChange: () => events.emit("connectivity-changed", undefined),
onError,
shouldCrashWrites: () => debugConfig.failingWrites
});
const {
addTransaction,
pendingTransactionCount,
withPendingTransactions
} = optimisticUi({
commitTransaction: push,
return cb(res, self.state.progressMatched)
}, self.state.progressMatched)
self.bus.emit('update', self.state.value, remaining(end))
}
self.state = {
id: tweens.length,
isRunning: false,
isRemoved: false,
progress: 0,
progressMatched: 0,
reversed: false,
repeats: 0
}
self.bus = new NanoEvents()
tweens.push(self)
self.use = function(enhancer) {
enhancer(self, _options)
return self
}
self.easing = function(easing) {
_options.easing = easing
return self
}
self.duration = function(duration) {
_options.duration = duration
return self
export function runWebsocketServer(params: Params) {
const { onAuthenticate, onChangeData, onRequestData } = params;
const serialization = params.serialization || jsonSerialization;
const events = new NanoEvents<{ change: KV }>();
const latestCopies: { [stringy: string]: undefined | ValueContainer } = {};
events.on("change", kv => {
latestCopies[stringy(kv)] = kv.value;
});
const listeningTo: string[] = [];
function getAndObserve(
key: K,
close: () => void,
onData: (value: ValueContainer) => void,
secWSKey: string
) {
events.on("change", eventKV => {
if (stringy(key) === stringy(eventKV)) onData(eventKV.value);
});