Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[feature request] Global actions #41

Open
jmarceli opened this issue Aug 1, 2016 · 7 comments
Open

[feature request] Global actions #41

jmarceli opened this issue Aug 1, 2016 · 7 comments

Comments

@jmarceli
Copy link
Contributor

jmarceli commented Aug 1, 2016

As described in #40 it will be nice to have an option of defining global actions. This is handy feature especially for integration with other react/redux libraries as they dispatch non-prefixed actions (e.g. react-router-redux).

I think that there are two options of global actions handling:

  1. Built in redux-elm feature, enabled with some configuration options
  2. Standalone package named e.g. redux-elm-global, which is mounted at the root application updater like any other redux-elm component

I think I would prefer standalone package as it is more modular approach and global actions feature is definitely not required by all redux-elm users.

I've created this issue to gather some opinions about this topic, so please write what do you think about it.

@eliperelman
Copy link

I don't think a separate global package is necessary. If this were to be a thing, I think just having the right API in this library would be enough.

@tomkis
Copy link
Collaborator

tomkis commented Oct 25, 2016

I kinda like an idea of allowing user to dispatch global actions, it may seem like a hack, but it's not, because redux-elm works very well with model in form of tree, but doesn't work well with normalized data (which may eventually be handy) so I perceieve this as a bridge between these two approaches.

@dgsunesen
Copy link

Where are we with this?

I have a case where I have a wrapper App component which updater looks something like this:

declare function require(name: string): any;

import { takeEvery } from "redux-saga";
import { take, put, call, fork, select, Effect } from "redux-saga/effects";
import { Map } from "immutable";

const { Updater } = require("redux-elm");

// Initial immutable model/state passed to the Updater.
type Init = () => Map<string, any>;
export const init: Init = () => Map({
  isSidebarOpen: false,
  isOptionsOpen: false
});

export default new Updater(init())
  .case("TOGGLE_SIDEBAR", model => model.set("isSidebarOpen", !model.get("isSidebarOpen")))
  .case("TOGGLE_OPTIONS", model => model.set("isOptionsOpen", !model.get("isOptionsOpen")))
  .toReducer();

How would I dispatch an action for TOGGLE_SIDEBAR from within a nested elm component from whereever in my app?

Right now, if I dispatch({type: "TOGGLE_SIDEBAR"}) from a nested elm component UserView, it actually dispatches UserView.TOGGLE_SIDEBAR..

Is it possible somehow to solve this?

Is it even possible?

@dvshur
Copy link

dvshur commented Jan 16, 2017

@dgsunesen, have you tried using a custom matcher?

http://salsita.github.io/redux-elm/custom-matchers/writing-custom-matcher.html

Using it, for example, you could listen to any event than ends with TOGGLE_SIDEBAR (however deeply nested in a tree) in a parent/grandparent updater.

I'm not sure if this approach would cover every possible use case, but sometimes you can get away with it.

@dgsunesen
Copy link

@dvshur - Thanks. I'll let you know if this solves my problem :-)

@qbolec
Copy link

qbolec commented Jul 29, 2017

How would one solve this problem in Elm?

Btw. I've found this project while trying to find an answer to my question about reusable components in Redux. I guess you are very qualified to answer it.

@jcheroske
Copy link
Contributor

jcheroske commented Jul 29, 2017 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

7 participants