The wrapper takes a link to the "raw" data provider and returns a new object that based on the original,
but all async methods and properties are wrapped by Async.
Notice, the wrapped methods can take additional Async parameters, like group or label.
// By default, all wrapped methods have a group name that is equal to the provider name. // So we can use it to clear or suspend requests, etc. $a.clearAll({group:'api.User'})
wrappedProvider.upd({uuid:1}, { // All wrapped methods can take additional Async parameters as the second argument: `group`, `label` and `join` group:'bla', label:'foo', join:true,
// Also, the second argument of the wrapped method can take the original parameters from a provider headers: { 'X-Foo':'1' }
}).then((res) => { console.log(res); });
// If we are providing a group to the method, it will be joined with the global group by using the `:` character $a.suspendAll({group:'api.User:bla'});
// Obviously, we can use a group as RegExp $a.muteAll({group: /api\.User/});
// We can use any methods or properties from the original data provider wrappedProvider.dropCache();
By default, when the wrapper wraps the provider, it takes the provider name and passes it as a group to all wrapped methods.
This behavior brings a future to clear or suspend all requests from the wrapped provider by its name.
But we can provide a different global name when wrapping a provider.
The wrapper takes a link to the "raw" event emitter and returns a new object that based on the original,
but all async methods and properties are wrapped by Async.
Notice, the wrapped methods can take additional Async parameters, like group or label. In addition,
the wrapper adds new methods, like "on" or "off", to make the emitter API more standard.
// We can safely listen to emitter events, cause all emitter methods, like `addListener` or `on` are wrapped by Async. constid = wrappedEventEmitter.addEventListener('scroll', handler, { // Notice, the third argument can take Async parameters in addition to the native emitter parameters capture:true, label:'label' });
// The wrapper preserves the original API of emitter methods, so we can call something like this wrappedEventEmitter.removeEventListener('scroll', handler);
// Finally, the wrapper adds a bunch of standard methods to the emitter, like `on`, `once`, and other stuff. // We can use their instead of the original methods to make our code more universal. wrappedEventEmitter.once('resize', (e) => { console.log(e); }, {group:'resizers'});
$a.muteAll({group:'resizers'});
// We can use any methods or properties from the original emitter console.log(wrappedEventEmitter.name); // window.name
Unlike the wrapper of data providers, the emitter wrapper doesn't have any default global group for operations,
but you can pass it manually.
This behavior brings a future to clear or suspend all events from the wrapped provider by its name.
wrappedEventEmitter.on('scroll', (e) => { console.log(e); }, { // If we are providing a group to the method, it will be joined with the global group by using the `:` character group:'scrolling' });
As you can see, the wrapper creates a new object based on the original emitter and replaces some methods with the safely Async analogs.
The overridden methods preserve the original emitter API, but some interfaces are not supported to use.
// The wrapper does not support this kind of attaching listeners. // The replaced method can take the second argument only as a function. wrappedEventEmitter.addEventListener('scroll', { handleEvent: (e) => { console.log(e); } })
The wrapper takes a link to the "raw" async storage and returns a new object that based on the original,
but all async methods and properties are wrapped by Async.
Notice, the wrapped methods can take additional Async parameters, like group or label.
wrappedStorage.set('someKey', 'someValue', { // All wrapped methods can take additional Async parameters as the last argument: `group`, `label` and `join` group:'bla', label:'foo', join:true, }).then(async () => { console.log(awaitwrappedStorage.get('someKey') === 'someValue'); });
The storage wrapper doesn't have any default global group for operations, but you can pass it manually.
This behavior brings a feature to clear or suspend all events from the wrapped provider by its name.
wrappedStorage.get('someKey', { // If we are providing a group to the method, it will be joined with the global group by using the `:` character group:'localGroup' }).then((val) => { console.log(val) === 'someValue'; });
// We can provide own global group to namespace, it will be joined with the parent's global group constblaStore = wrappedStorage.namespace('[[BLA]]', {group:'bla'});
core/async/modules/wrappers
This module provides a bunch of helpers to wrap some objects, like event emitters or data providers.
wrapDataProvider
The wrapper takes a link to the "raw" data provider and returns a new object that based on the original, but all async methods and properties are wrapped by Async.
Notice, the wrapped methods can take additional Async parameters, like group or label.
Custom global group
By default, when the wrapper wraps the provider, it takes the provider name and passes it as a group to all wrapped methods. This behavior brings a future to clear or suspend all requests from the wrapped provider by its name. But we can provide a different global name when wrapping a provider.
wrapEventEmitter
The wrapper takes a link to the "raw" event emitter and returns a new object that based on the original, but all async methods and properties are wrapped by Async.
Notice, the wrapped methods can take additional Async parameters, like group or label. In addition, the wrapper adds new methods, like "on" or "off", to make the emitter API more standard.
Custom global group
Unlike the wrapper of data providers, the emitter wrapper doesn't have any default global group for operations, but you can pass it manually. This behavior brings a future to clear or suspend all events from the wrapped provider by its name.
Native API of emitters
As you can see, the wrapper creates a new object based on the original emitter and replaces some methods with the safely Async analogs. The overridden methods preserve the original emitter API, but some interfaces are not supported to use.
wrapStorage
The wrapper takes a link to the "raw" async storage and returns a new object that based on the original, but all async methods and properties are wrapped by Async.
Notice, the wrapped methods can take additional Async parameters, like group or label.
Custom global group
The storage wrapper doesn't have any default global group for operations, but you can pass it manually. This behavior brings a feature to clear or suspend all events from the wrapped provider by its name.
Custom namespace
By default, a custom namespace have the same global group as the global namespace