Objective Redux

Redux made better, objectively.

Code Splitting

If you need to call an action from outside your package, you can give the action a name using the withAddressableName method.


// For Reducers
class MyControllerClass extends StateController {
  // ...
  setSwitch = this.registerAction(
    (state, isOn) => ({ isOn })
  ).withAddressableName('SET_SWITCH_STATE'); // <--
}

// For Sagas
class MyControllerClass extends StatelessController {
  // ...
  toggleSwitch = this.createSaga()
    .withEffect(configureTakeLatest())
    .withAddressableName('SET_SWITCH_STATE') // <--
    .register(
      function *() {
        const myController = yield getControllerFromSagaContext(MyController);
        yield myController.myAction(payload);
      }
    );
}

You may also want to allow your controller to be initialized when a non-Objective-Redux action is performed. This ensures that, if an action targeting your controller is fired before you've used the getInstance method for that controller in your application, Objective-Redux can find the controller to handle the event.


MyControllerClass.initializeOnExternalAction();

Then, your reducer or saga can be called with


const myAction = createAction(
  getActionNameForController('My-Controller', 'SET_SWITCH_STATE')
);
// The ObjectiveStore instance will see that the action targets MyControllerClass. It will
// call MyControllerClass.getInstance(objectiveStore) for you to initialize the controller
// prior to the action being fired.
objectiveStore.dispatch(myAction(isOn));