3.0.0 • Published 1 year ago

ember-collector-dispatcher v3.0.0

Weekly downloads
1
License
MIT
Repository
github
Last release
1 year ago

ember-collector-dispatcher

Build Status GitHub version NPM version Dependency Status codecov Greenkeeper badge Ember Observer Score

Information

NPM

Collect and dispatch elements in your progressive web app.

Installation

ember install ember-collector-dispatcher

Configuring your collector

You need to extend the collector service:

// app/services/my-collector.js

export default Collector.extend({
  adapters: [
    ['indexed-db', { database: 'logs' }],
    ['local-storage', { key: 'logs' }],
    'memory'
  ]
});

You also need to define adapters with the possible storages. Now, you can choose: indexeddb, local-storage and memory.

You can add as many adapters as you want. Only must implements the following methods:

MethodDescription
isSupportedReturns true if the storage is supported; otherwise, false.
countReturns the number of elements in the storage.
pushAdds one or more elements to the end of the storage.
unshiftAdds one or more elements to the beginning of the storage.
popRemoves one or more elements from the end of the storage and returns that elements.
shiftRemoves one or more elements from the beginning of the storage and returns that elements.

Configuring your dispatcher

You need to extend the dispatcher service:

// app/services/my-dispatcher.js

export default Dispatcher.extend({
  collector: service('my-collector'),
  maxTimeout: 30000,
  maxConcurrent: 5,

  async dispatch(items) {
    // my dispatch logic...

    return [undispatchedItems];
  }
})

You also need to define the following properties:

PropertyDescription
collectorCollector service injection.
maxTimeoutMax time, in milliseconds (thousandths of a second), the dispatcher should wait before the dispatch method is executed.
maxConcurrentMax number of items that the dispatcher can be process during the loop.
dispatchDispatch items as you want

Contribute

If you want to contribute to this addon, please read the CONTRIBUTING.md.

Versioning

We use SemVer for versioning. For the versions available, see the tags on this repository.

Authors

See the list of contributors who participated in this project.

License

This project is licensed under the MIT License - see the LICENSE.md file for details