Skip to content

Event interceptors #41

Closed
dmitry-korolev opened this issue Jul 27, 2018 · 2 comments
Closed

Event interceptors #41

dmitry-korolev opened this issue Jul 27, 2018 · 2 comments
Labels
enhancement New feature or request RFC Request for comments stapp-core

Comments

@dmitry-korolev
Copy link
Contributor

dmitry-korolev commented Jul 27, 2018

TBD

@dmitry-korolev dmitry-korolev added enhancement New feature or request RFC Request for comments stapp-core labels Jul 27, 2018
@berezinmv
Copy link
Collaborator

berezinmv commented Jul 31, 2018

Problem

We need to modify event payload before it goes through reducers and epics.

Solution

Interceptor

Declare 'Interceptor' type. Interceptor is a function that accepts and returns event. Also, if interceptor returns null or undefined we assume that event have been canceled.

type Interceptor<T extends Event> = (event: T) => T?

Module

Extend 'Module' type with 'interceptors' property

type Module = {
  ...
  interceptors?: Interceptor[];
}

Helper

Create helper function to intercept only given type of events.

function createInterceptor(eventCreator, (event: Event) => Event?): Interceptor;

Usage

const unmaskValueInterceptor = createInterceptor(setValue, event => {
  event.payload = unmaskPayloadValues(event.payload)
  return event
})

const unmaskModule = {
  name: 'unmask',
  interceptors: [unmaskValueInterceptor]
};

@dmitry-korolev dmitry-korolev modified the milestones: 2.1.0, 2.2.0 Aug 3, 2018
@dmitry-korolev dmitry-korolev modified the milestones: 2.2.0, 2.3.0 Aug 12, 2018
@dmitry-korolev dmitry-korolev modified the milestones: 2.3.0, 2.4.0 Aug 20, 2018
@dmitry-korolev dmitry-korolev removed this from the 2.4.0 milestone Aug 22, 2018
@dmitry-korolev
Copy link
Contributor Author

I think it can be done with plugins. Closing it temporary.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement New feature or request RFC Request for comments stapp-core
Projects
None yet
Development

No branches or pull requests

2 participants