Skip to content

Releases: pauldijou/redux-act

1.1.1

26 Feb 16:08
Compare
Choose a tag to compare

Just publishing TypeScript typings. No code changes.

1.1.0

14 Oct 20:37
Compare
Choose a tag to compare

Support numbers in serializable actions.

1.0.0

04 Sep 21:13
Compare
Choose a tag to compare

After months without any change, time to move to 1.0.0. Removing deprecated binded function in favor of the bound one.

0.5.0

15 Jun 19:02
Compare
Choose a tag to compare

Remove meta key from action if no meta-reducer provided.

0.4.2

13 May 09:24
Compare
Choose a tag to compare

Add browserify in order to compile a standalone file.

0.4.1

04 May 21:39
Compare
Choose a tag to compare

Add types API to help testing.

0.4.0

13 Feb 15:04
Compare
Choose a tag to compare

So, it wasn't the last release before 1.0 after all...

⚠️ Breaking changes

They shouldn't actually break your app because they are well hidden but I need to mention them. Before, the generated id was placed in both a "private" property __id__ and the type property (with the optional description appended to it). I did that to maximize safety when checking the id and to boost performance because comparing numbers is blazing fast.

After a lot of thoughts, it wasn't worth it. It's blocking compatibility with other Redux libs and do not rely on the type anymore like it should regarding Redux document. So in this release, redux-act is dropping the __id__ property and will only rely on the type. Since the id is still put in there, it will not clash, not even with non-redux-act actions (except if you have crazy types like const TYPE = '[42] Whatever, yolo'). See the compatibility section for more infos.

Fix typo

Because I'm not that good in English, I wrote binded instead of bound (thanks @appsforartists). The method has been renamed. The wrong one will be deprecated with a warning and removed in the 1.0.

Loggers

I started working a better logger support for redux-act actions, especially batch actions. Check the loggers section for more infos. Only Redux Logger is supported right now, but you can open an issue or submit a pull request to ask for any other logger.

0.3.0

22 Dec 10:17
Compare
Choose a tag to compare

This is probably the last release before 1.0. Just wanted to battle test it in production before freezing the API.

⚠️ Breaking changes (sorry...)

bindTo has been renamed to assignTo. There is still a bindTo function, but now, it returns a new action creator rather than mutating the existing one. This is in order to both be closer to the actual bind function (which return a new function) and offer better support for immutability and server side code (where you have common actions for all requests but a store for each one, so mutating isn't an option). Just do a global find and replace of bindTo to assignTo and bindAll to assignAll and you are good to go!

assignTo and assignAll

Those functions replace bindTo and bindAll. Same feature.

bindTo and bindAll

Now returns a new action creator which will act just like the original one but no longer mutate it.

dispatch function or store object

When passing a store to bindTo, assignTo, bindAll or assignAll, you can now also pass a dispatch function. This might come handy if you want to do the binding inside an connect function from react-redux where you only have access to the dispatch function.

import store from './store';

// This code...
const bindedAction = createAction().bindTo(store);
// Is equal to
const bindedAction = creatAction().bindTo(store.dispatch);

batch

redux-act now supports batched actions. You should know that each dispatched action will trigger all listeners on the store. Some libs rely on that, react-redux might re-render it's wrapped React component for example. So if you need to dispatch several actions at once to update different parts of your store, rather than creating a meta-action that do all the stuff inside the reducer, you can batch them so they will all be applied inside only one dispatch.

batch is an action creator like any other created using createAction. You can assign or bind it if you want, especially if you only have one store. You can even use inside reducers. It is enabled by default, but you can remove it and put it back. See README for more examples.

import { dispatch } from './store';

const a1 = createAction();
const a2 = createAction();
const a3 = createAction();

// -- Default strategy
dispatch(a1());
// -> trigger all store listeners
dispatch(a2());
// -> trigger all store listeners
dispatch(a3());
// -> trigger all store listeners

// -- Batched strategy
import { batch } from 'redux-act';
dispatch(batch(a1(), a2(), a3()));
// -> trigger all store listeners only once

// You can also use an array if you want
dispatch(batch([a1(), a2(), a3()]));

⚠️ Warning This does not work with binded or assigned action creators. They need to return an action object, not automatically dispatch it. If you are using those features (because, you know, they are awesome), you can call the raw method to retrieve the action object directly without dispatching it.

// Assigned action creators
const a1 = createAction();
const a2 = createAction();
a1.assignTo(store);
a2.assignTo(store);
store.dispatch(batch(a1.raw(), a2.raw()));

// Binded action creators
const a1 = createAction().bindTo(store);
const a2 = createAction().bindTo(store);
store.dispatch(batch(a1.raw(), a2.raw()));

You can do some other funny stuff, just because.

import { batch, disbatch, createAction } from 'redux-act';
import store from './store';

const a1 = createAction();
const a2 = createAction();

// All the following samples do the exact same thing.
// (and each time, you have both syntax, using or not an array)

// Basic batch
store.dispatch(batch(a1(), a2()));
store.dispatch(batch([a1(), a2()]));

// Disbatch from a store
disbatch(store, a1(), a2());
disbatch(store, [a1(), a2()]);

// Disbatch from a dispatch function
disbatch(store.dispatch, a1(), a2());
disbatch(store.dispatch, [a1(), a2()]);

// Add the disbatch method to the store and use it
disbatch(store);
store.disbatch(a1(), a2());
store.disbatch([a1(), a2()]);

Action creator status

You can now test the status of an action creator.

const action = createAction();
const store = createStore(() => 0);

action.assigned(); // false, not assigned
action.binded(); // false, not binded
action.dispatched(); // false, test if either assigned or binded

action.assignTo(store);
action.assigned(); // true
action.binded(); // false
action.dispatched(); // true

const bindedAction = action.bindTo(store);
bindedAction.assigned(); // false
bindedAction.binded(); // true
bindedAction.dispatched(); // true

0.2.0

29 Sep 22:14
Compare
Choose a tag to compare

Metadata

You can now have some metadata. It's just as the payload, you need a function to reduce the arguments as a metadata object and it will be the third argument inside the reducer.

const doStuff = createAction('do some stuff', arg => arg, (one, two)=> {so: 'meta'});
const reducer = createReducer({
  [doStuff]: (state, payload, meta)=> payload
});

Serializable actions

Sometimes, you need to share actions between client and server, or between clients. You can no longer rely on id generated at runtime, you need to use strict manually provided constants. That's not the main goal of the lib, but if you really need it, just use a fully uppercase description and it will be use as the id.

const serializedDoStuff = createAction('DO_STUFF', arg => arg, (one, two)=> {so: 'meta'});

0.1.1

20 Aug 09:30
Compare
Choose a tag to compare

Use a more private id key for better support of non redux-act actions.