Giter Site home page Giter Site logo

Custom action matchers in Saga about prism HOT 5 CLOSED

tomsdev avatar tomsdev commented on May 25, 2024
Custom action matchers in Saga

from prism.

Comments (5)

tomsdev avatar tomsdev commented on May 25, 2024 1

I'm not sure what you mean exactly by "explicit rather than implicit action wrapping in Sagas". In Elm, the side effects are declared in the Updater so the way to take() actions that involve side effects is exactly the same as actions that just change the state. Even if in redux-elm the side effects are now declared outside of the Updater (e.g. in local sagas), I'd still expect consistency (and as much power) in the way I can take() actions and in the way they are wrapped or unwrapped.That's why I'm proposing to have the same custom action matchers this library provide for the Updater.

from prism.

tomkis avatar tomkis commented on May 25, 2024

Custom action matchers are available in the Updater but not in Saga. As I understand it, at the moment the saga can only take() an action that is local to the component (e.g. wrapped).

Actually take or takeEvery can take predicate as an argument therefore this custom logic can be implemented in Sagas as well... the question is though, should this be part of the framework? Since I believe that this should live in userland.

One use case would be a global 'REFRESH' action fired in the app that would need each component saga to fetch their data again.

I don't think this would be possible even with Custom matcher, maybe it wouldn't even make sense to implement it this way. I am in favour of explicit rather than implicit action wrapping in Sagas.

from prism.

tomkis avatar tomkis commented on May 25, 2024

Could you provide some code snippet about what you have envisioned?

from prism.

tomkis avatar tomkis commented on May 25, 2024

Since 3.x will support RxJS Sagas and action matching is totally separated from rest of the architecture in favour of #4 I can imagine we could nicely re-use the matching even in Sagas.

const initialState = {
  incremented: 0,
  decremented: 0
};

const reducer = new MatchingReducerFactory(initialState)
  .case('Incremented', model => ({...model, incremented: model.incremented + 1}))
  .case('Decremented', model => ({...model, decremented: model.decremented + 1}))
  .toReducer();

export default action$ => action$
  .scan(reducer)
  .filter(state => state.incremented >= 3 && state.decremented >= 3)
  .map(() => ({ type: 'ShowPopup' }))
  .take(1);

from prism.

tomkis avatar tomkis commented on May 25, 2024

Closing, solved by Saga & matchers decoupling in v3.

from prism.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.