rel-events
Advanced tools
Comparing version 0.4.4-beta.3 to 0.4.4
@@ -70,35 +70,2 @@ | ||
### Event Chaining - Making Events listen to Events | ||
Sometimes, we want to make an Event be triggered by the completion of another. Let's imagine that, after logging in an user, we need to go somewhere to get the user's data. | ||
Assuming you've implemented the `LoginHTTPEvent` as the example above, you'll need to implement your new Event and EventManager to fetch the user's data. After implementing, you just need to pass the `listenTo` key to your new event. | ||
```js | ||
// on events.js | ||
import { HTTPEvent } from 'rel-events'; | ||
import { LoginHTTPEventManager, FetchUserDataHTTPEventManager } from './eventManagers.js'; | ||
export const LoginHTTPEvent = new HTTPEvent({ | ||
name: 'login', | ||
manager: new LoginHTTPEventManager(), | ||
}); | ||
// to chain an event to another, declare the `listenTo` key. | ||
// and, yes, you may make an event listen to multiple events. | ||
// be careful not to pass the direct reference to LoginHTTPEvent; | ||
// pass a function that returns it instead. | ||
export const FetchUserDataHTTPEvent = new HTTPEvent({ | ||
name: 'fetchUserData', | ||
manager: new FetchUserDataHTTPEventManager(), | ||
listenTo: [ | ||
{ event: () => LoginHTTPEvent, triggerOn: 'success' }, | ||
] | ||
}); | ||
``` | ||
That means that, whenever the login is successful, `fetchUserData` will be triggered by calling `FetchUserDataHTTPEventManager.call` passing the data from the `LoginHTTPEvent.onSuccess` return. | ||
**One caveat** is that the `event` value is **not** a direct reference to the Event that will be listened to. Instead, it's a function that returns the reference. That's needed because we could be using multiple files for multiple Events, and, if we do, we can't guarantee that `FetchUserDataHTTPEvent` will be loaded into memory before `LoginHTTPEvent`. If that happened, the `event` value would be `undefined`, so we chose to receive a function instead. | ||
### `useDataFrom` optional Event parameter | ||
@@ -105,0 +72,0 @@ |
@@ -8,4 +8,5 @@ # rel-events docs | ||
- [3: Advanced Usage](https://github.com/labcodes/rel-events/tree/master/docs/3-Advanced-Usage.md) | ||
- [4: API docs](https://github.com/labcodes/rel-events/tree/master/docs/4-API-docs.md) | ||
- [5: How it works](https://github.com/labcodes/rel-events/tree/master/docs/5-How-it-works.md) | ||
- [6: Contributing](https://github.com/labcodes/rel-events/tree/master/docs/6-Contributing.md) | ||
- [4: Chaining Events](https://github.com/labcodes/rel-events/tree/master/docs/4-Chaining-Events.md) | ||
- [5: API docs](https://github.com/labcodes/rel-events/tree/master/docs/5-API-docs.md) | ||
- [6: How it works](https://github.com/labcodes/rel-events/tree/master/docs/6-How-it-works.md) | ||
- [7: Contributing](https://github.com/labcodes/rel-events/tree/master/docs/7-Contributing.md) |
{ | ||
"name": "rel-events", | ||
"version": "0.4.4-beta.3", | ||
"version": "0.4.4", | ||
"description": "The relevant React Events Library. Events framework based on redux to decouple our from business logic and make state management easy.", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Deprecated
MaintenanceThe maintainer of the package marked it as deprecated. This could indicate that a single version should not be used, or that the package is no longer maintained and any new vulnerabilities will not be fixed.
Found 1 instance in 1 package
175470
27
0