Socket
Socket
Sign inDemoInstall

rel-events

Package Overview
Dependencies
Maintainers
2
Versions
21
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

rel-events - npm Package Compare versions

Comparing version 0.4.4-beta.3 to 0.4.4

docs/4-Chaining-Events.md

33

docs/3-Advanced-Usage.md

@@ -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 @@

7

docs/README.md

@@ -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",

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc