How to use nanoevents - 3 common examples

To help you get started, we’ve selected a few nanoevents examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github citrusbyte / oncilla / src / core / create.ts View on Github external
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,
github Kelin2025 / nanotween / index.js View on Github external
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
github citrusbyte / oncilla / src / network / websockets / server / index.ts View on Github external
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);
    });

nanoevents

Simple and tiny (107 bytes) event emitter library

MIT
Latest version published 2 months ago

Package Health Score

80 / 100
Full package analysis

Popular nanoevents functions