How to use the event-target-shim.EventTarget function in event-target-shim

To help you get started, we’ve selected a few event-target-shim 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 ArcBlock / forge-js / apps / forge-web / src / libs / hooks.js View on Github external
}, [callback]);

  // Set up the interval.
  // eslint-disable-next-line
  useEffect(() => {
    function tick() {
      savedCallback.current();
    }
    if (delay !== null) {
      const id = setInterval(tick, delay);
      return () => clearInterval(id);
    }
  }, [delay]);
}

const evtTarget = new EventTarget();
const useStorage = (storage, keyPrefix) => (key, defaultValue) => {
  const storeKey = `${keyPrefix}.${key}`;
  const raw = storage.getItem(storeKey);
  const [value, setValue] = useState(raw ? JSON.parse(raw) : defaultValue);

  const updater = updatedValue => {
    setValue(updatedValue);
    storage.setItem(storeKey, JSON.stringify(updatedValue));
    evtTarget.dispatchEvent(new CustomEvent('storage_change', { detail: { key } }));
  };

  if (defaultValue != null && !raw) {
    updater(defaultValue);
  }

  useEffect(() => {
github Buzut / huge-uploader / src / index.js View on Github external
this.retries = params.retries || 5;
        this.delayBeforeRetry = params.delayBeforeRetry || 5;

        this.start = 0;
        this.chunk = null;
        this.chunkCount = 0;
        this.totalChunks = Math.ceil(this.file.size / (this.chunkSize * 1000 * 1000));
        this.retriesCount = 0;
        this.offline = false;
        this.paused = false;

        this.headers['uploader-file-id'] = this._uniqid(this.file);
        this.headers['uploader-chunks-total'] = this.totalChunks;

        this._reader = new FileReader();
        this._eventTarget = new EventTarget();

        this._validateParams();
        this._sendChunks();

        // restart sync when back online
        // trigger events when offline/back online
        window.addEventListener('online', () => {
            if (!this.offline) return;

            this.offline = false;
            this._eventTarget.dispatchEvent(new Event('online'));
            this._sendChunks();
        });

        window.addEventListener('offline', () => {
            this.offline = true;

event-target-shim

An implementation of WHATWG EventTarget interface.

MIT
Latest version published 4 years ago

Package Health Score

67 / 100
Full package analysis