From 643522546726d0f077b5aa4f762c57519f6766f4 Mon Sep 17 00:00:00 2001 From: Richard Ng Date: Sat, 18 May 2019 09:06:32 +0100 Subject: [PATCH 1/4] reorganise sidebar somewhat --- docs/README.md | 2 +- docs/create/README.md | 6 ++++-- website/i18n/en.json | 7 ++++--- website/sidebars.json | 6 ++++-- 4 files changed, 13 insertions(+), 8 deletions(-) diff --git a/docs/README.md b/docs/README.md index 88f56465..97d0d6cb 100644 --- a/docs/README.md +++ b/docs/README.md @@ -2,7 +2,7 @@ id: redux-leaves title: Core API hide_title: true -sidebar_label: reduxLeaves +sidebar_label: reduxLeaves API --- # `reduxLeaves(initialState, [reducersDict = {}])` diff --git a/docs/create/README.md b/docs/create/README.md index 9c4cd328..0a08110d 100644 --- a/docs/create/README.md +++ b/docs/create/README.md @@ -2,10 +2,12 @@ id: creators title: Action Creators hide_title: true -sidebar_label: Action creators +sidebar_label: Actions --- -# Action Creators +# `actions` + +## Action creators With Redux-Leaves, all [leaf reducers](../leafReducers.md) that you define in your [`reducersDict`](../README.md#reducersdict) are automatically given a corresponding action creator. diff --git a/website/i18n/en.json b/website/i18n/en.json index 2ee76d52..3c086327 100644 --- a/website/i18n/en.json +++ b/website/i18n/en.json @@ -73,7 +73,7 @@ }, "redux-leaves": { "title": "Core API", - "sidebar_label": "reduxLeaves" + "sidebar_label": "reduxLeaves API" } }, "links": { @@ -84,8 +84,9 @@ }, "categories": { "Introduction": "Introduction", - "Core API": "Core API", - "Actions": "Actions" + "Leaves & Reducers": "Leaves & Reducers", + "Actions": "Actions", + "Default creators": "Default creators" } }, "pages-strings": { diff --git a/website/sidebars.json b/website/sidebars.json index 5ef7ce38..c0a6794c 100644 --- a/website/sidebars.json +++ b/website/sidebars.json @@ -5,7 +5,7 @@ "intro/demo", "intro/features" ], - "Core API":[ + "Leaves & Reducers":[ "redux-leaves", "leaf/about", "leaf-reducers", @@ -13,7 +13,9 @@ ], "Actions": [ "create/creators", - "leaf/standard-actions", + "leaf/standard-actions" + ], + "Default creators": [ "create/defaults", "create/type-specific", { From 6dfdf75aa9030a09a9eab59a57972b63a95c31bd Mon Sep 17 00:00:00 2001 From: Richard Ng Date: Sat, 18 May 2019 09:09:44 +0100 Subject: [PATCH 2/4] make actions documentation slightly more concise --- docs/create/README.md | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/docs/create/README.md b/docs/create/README.md index 0a08110d..efbe17c1 100644 --- a/docs/create/README.md +++ b/docs/create/README.md @@ -9,9 +9,7 @@ sidebar_label: Actions ## Action creators -With Redux-Leaves, all [leaf reducers](../leafReducers.md) that you define in your [`reducersDict`](../README.md#reducersdict) are automatically given a corresponding action creator. - -The action creator has a [creator key](../creatorKeys.md) (`creatorKey`) corresponding to the one which the leaf reducer is defined with. +With Redux-Leaves, all [leaf reducers](../leafReducers.md) that you define in your [`reducersDict`](../README.md#reducersdict) are automatically given a corresponding action creator, keyed by the same [`creatorKey`](../creatorKeys.md). `create[creatorKey]` is then an action creator function available at every single [leaf](../leaf/README.md) on our `actions` object. From 2361161d8e8034dfd4ea25aa78843fd934faecbb Mon Sep 17 00:00:00 2001 From: Richard Ng Date: Sat, 18 May 2019 09:40:41 +0100 Subject: [PATCH 3/4] reorganise linking for new sidebars --- docs/create/asArray/README.md | 4 +- docs/create/asBoolean/README.md | 4 +- docs/create/asNumber/README.md | 4 +- docs/create/asObject/README.md | 4 +- docs/create/asString/README.md | 4 +- docs/create/defaults.md | 15 ++- docs/create/typeSpecific.md | 2 +- docs/customReducers.md | 221 -------------------------------- docs/customReducers.spec.js | 176 ------------------------- docs/intro/README.md | 6 +- docs/leafReducers.md | 4 +- website/i18n/en.json | 6 +- website/pages/en/index.js | 2 +- 13 files changed, 29 insertions(+), 423 deletions(-) delete mode 100644 docs/customReducers.md delete mode 100644 docs/customReducers.spec.js diff --git a/docs/create/asArray/README.md b/docs/create/asArray/README.md index a6df860d..8099fcc9 100644 --- a/docs/create/asArray/README.md +++ b/docs/create/asArray/README.md @@ -9,7 +9,7 @@ sidebar_label: Array Every single leaf on our `actions` object has access to `create.asArray` methods. -If the leaf was initialised with array state, then these methods are also accessible directly through the [`create` API](../README.md). +If the leaf was initialised with array state, then these methods are also accessible directly through the [`create` API](../defaults.md). If the current `leafState` is *not* an array, then it is first coerced into an array via lodash's [`_.toArray(leafState)`](https://lodash.com/docs/4.17.11#toArray) method, before the state is updated according to the action dispatched. @@ -19,7 +19,7 @@ If the current `leafState` is *not* an array, then it is first coerced into an a - [`.filter(callback)`](#filter(callback)) - [`.push(element, [index = -1], [replace = false])`](#createpushelement-index---1-replace--false) -[Back to all `create` action creators](../README.md#action-creators) +[Back to all `create` action creators](../defaults.md) ## `concat(array)` **`create.asArray.concat`** diff --git a/docs/create/asBoolean/README.md b/docs/create/asBoolean/README.md index 5a9b0cfa..07813663 100644 --- a/docs/create/asBoolean/README.md +++ b/docs/create/asBoolean/README.md @@ -9,7 +9,7 @@ sidebar_label: Boolean Every single leaf on our `actions` object has access to `create.asBoolean` methods. -If the leaf was initialised with boolean state, then these methods are also accessible directly through the [`create` API](../README.md). +If the leaf was initialised with boolean state, then these methods are also accessible directly through the [`create` API](../defaults.md). If the current `leafState` is *not* a boolean, then it is first coerced into a boolean as `!!leafState`, before the state is updated according to the action dispatched. @@ -18,7 +18,7 @@ If the current `leafState` is *not* a boolean, then it is first coerced into a b - [`.on()`](#on) - [`.toggle()`](#toggle) -[Back to all `create` action creators](../README.md#action-creators) +[Back to all `create` action creators](../defaults.md) ## `off()` **`create.asBoolean.off`** diff --git a/docs/create/asNumber/README.md b/docs/create/asNumber/README.md index 47d3f023..b54191eb 100644 --- a/docs/create/asNumber/README.md +++ b/docs/create/asNumber/README.md @@ -9,14 +9,14 @@ sidebar_label: Number Every single leaf on our `actions` object has access to `create.asNumber` methods. -If the leaf was initialised with number state, then these methods are also accessible directly through the [`create` API](../README.md). +If the leaf was initialised with number state, then these methods are also accessible directly through the [`create` API](../defaults.md). If the current `leafState` is *not* a number, then it is first coerced into an array via lodash's [`_.toNumber(leafState)`](https://lodash.com/docs/4.17.11#toNumber) method, before the state is updated according to the action dispatched. ## Action creators - [`.increment([n = 1])`](#incrementn--1) -[Back to all `create` action creators](../README.md#action-creators) +[Back to all `create` action creators](../defaults.md) ## `increment([n = 1])` **`create.asNumber.increment`** diff --git a/docs/create/asObject/README.md b/docs/create/asObject/README.md index 3ed571f2..a0f12ec0 100644 --- a/docs/create/asObject/README.md +++ b/docs/create/asObject/README.md @@ -9,7 +9,7 @@ sidebar_label: Object Every single leaf on our `actions` object has access to `create.asObject` methods. -If the leaf was initialised with [plain object](https://lodash.com/docs/4.17.11#isPlainObject) state, then these methods are also accessible directly through the [`create` API](../README.md). +If the leaf was initialised with [plain object](https://lodash.com/docs/4.17.11#isPlainObject) state, then these methods are also accessible directly through the [`create` API](../defaults.md). If the current `leafState` is *not* a plain object, then it is first coerced into a plain object via lodash's [`_.toPlainObject(leafState)`](https://lodash.com/docs/4.17.11#toPlainObject) method, before the state is updated according to the action dispatched. @@ -17,7 +17,7 @@ If the current `leafState` is *not* a plain object, then it is first coerced int - [`.assign(...sources)`](#assignsources) - [`.set(path, value)`](#setpath-value) -[Back to all `create` action creators](../README.md#action-creators) +[Back to all `create` action creators](../defaults.md) ## `assign(...sources)` **`create.asObject.assign`** diff --git a/docs/create/asString/README.md b/docs/create/asString/README.md index fef9cf34..aa4820be 100644 --- a/docs/create/asString/README.md +++ b/docs/create/asString/README.md @@ -9,7 +9,7 @@ sidebar_label: String Every single leaf on our `actions` object has access to `create.asString` methods. -If the leaf was initialised with string state, then these methods are also accessible directly through the [`create` API](../README.md). +If the leaf was initialised with string state, then these methods are also accessible directly through the [`create` API](../defaults.md). If the current `leafState` is *not* a string, then it is first coerced into a string via lodash's [`_.toString(leafState)`](https://lodash.com/docs/4.17.11#toString) method, before the state is updated according to the action dispatched. @@ -17,7 +17,7 @@ If the current `leafState` is *not* a string, then it is first coerced into a st - [`.concat(...strings)`](#concatstrings) - [`.replace(pattern, replacement)`](#replacepattern-replacement) -[Back to all `create` action creators](../README.md#action-creators) +[Back to all `create` action creators](../defaults.md) ## `concat(...strings)` **`create.asString.concat`** diff --git a/docs/create/defaults.md b/docs/create/defaults.md index d3d55c28..837c1c7b 100644 --- a/docs/create/defaults.md +++ b/docs/create/defaults.md @@ -2,14 +2,19 @@ id: defaults title: Default Action Creators hide_title: true -sidebar_label: Default action creators +sidebar_label: Universal --- # `create` -Every single leaf on our `actions` object has a `create` property, through which we can access action creator functions. +Every single [leaf](../leaf/README.md) on our [`actions`](README.md) object has a `create` property, through which we can access action creator functions corresponding to the [`reducersDict`](../README.md#reducersdict) passed to to [`reduxLeaves`](../README.md). + +In addition, `create` also contains a number of default action creators, which are listed below. + +The default action creators can be overwritten by supplying your own [leaf reducer](../leafReducers.md) definition (with the same [`creatorKey`](../creatorKeys.md)) in your `reducersDict`. ## Action creators +### Universal - [`.apply(callback)`](#applycallback) - [`.clear([toNull = false])`](#cleartonull--false) - [`.reset()`](#reset) @@ -24,16 +29,14 @@ These are [spread into the `create` object](typeSpecific.md) depending on the `i - [`create.asObject`](asObject/README.md#createasobject) - [`create.asString`](asString/README.md#createasstring) -### Custom - -It is also possible to add [custom action creators](../customReducers.md) by passing in a `customReducers` argument to [`reduxLeaves`](../README.md). - ## `apply(callback)` **`create.apply`** Returns an object that, *when dispatched to a store created with the original state tree*, updates the leaf's state to the return value of `callback(leafState, entireState)`. +*Note: creating an action using `apply(callback)` violates Redux's recommendation that [actions should always be serializable](https://redux.js.org/faq/actions#why-should-type-be-a-string-or-at-least-serializable-why-should-my-action-types-be-constants), since the resultant action will have the function `callback` as its `payload`.* + ### Parameters - `callback` *(function)*: invoked by the leaf's reducer with two arguments, `leafState` and `entireState` diff --git a/docs/create/typeSpecific.md b/docs/create/typeSpecific.md index 9794656b..9c8c6cb4 100644 --- a/docs/create/typeSpecific.md +++ b/docs/create/typeSpecific.md @@ -2,7 +2,7 @@ id: type-specific title: Type-Specific Action Creators hide_title: true -sidebar_label: Type-specific creators +sidebar_label: Type-specific --- # Type-specific `create` methods diff --git a/docs/customReducers.md b/docs/customReducers.md deleted file mode 100644 index c823b0a3..00000000 --- a/docs/customReducers.md +++ /dev/null @@ -1,221 +0,0 @@ ---- -id: custom-reducers -title: Advanced Usage -hide_title: true -sidebar_label: customReducers ---- - -# `customReducers` - -The [`create` API](create/defaults.md) comes with several action creators, which our initialised `reducer` already knows how to respond to. - -However, perhaps we want to initialise with a custom action creator and reducer reducers. - -This is what the `customReducers` object is for, passed in as a second (optional) argument to [`reduxLeaves`](README.md). - -- [Shape of `customReducers`](#shape-of-customreducers) - - [Function shorthand](#function-shorthand) - - [Object longhand](#object-longhand) -- [Example 1: custom action creator with no arguments](#example-1-custom-action-creator-with-no-arguments) -- [Example 2: custom action creator using `payload` and `wholeState`](#example-2-custom-action-creator-using-payload-and-wholestate) -- [Example 3: more detailed customisation with `argsToPayload`](#example-3-more-detailed-customisation-with-argstopayload-and-type) - - -## Shape of `customReducers` - -### Function shorthand - -`customReducers` is an object which, at its simplest, is `key`-`value` pairings where: -- `key`: the name of the custom action creator, -- `value` *(function)*: updates the leaf state to its return value, invoked with `leafState`, `{ payload }` and `wholeState`. - -For example: -```js -const customReducers = { - incrementByTwo: leafState => leafState + 2, - decrementBy: (leafState, { payload }) => leafState - payload -} -``` - -This enables us to create actions for a given leaf in the following way: -```js -const { create } = actions.path.to.leaf - -const incByTwoAction = create.custom.incrementByTwo() -const decrementByThreeAction = create.custom.decrementBy(3) // 3 becomes the action payload -``` - -### Object longhand - -The notation above is shorthand for the following: - -```js -const customReducers = { - incrementByTwo: { - reducer: leafState => leafState + 2 - }, - decrementBy: { - reducer: (leafState, { payload }) => leafState - payload - } -} - -// create.custom.decrementBy(4, 5) will have a payload of 9 -``` - -Using longhand lets us customise further, e.g.: - -```js -const customReducers = { - decrementBySumOf: { - argsToPayload: (first, second) => first + second, - reducer: (leafState, { payload }) => leafState - payload - } -} -``` -Every logic object can have the following properties: -- `reducer` *(function)*: updates the leaf state to its return value, invoked with `leafState`, `{ payload }` and `wholeState` -- `argsToPayload` *(function, optional)*: takes the arguments passed to the action creator such that its return value becomes the action payload -- `type` *(string, optional)*: overrides the default `reduxLeaves`-generated action type (but does not affect reducer behaviour - the effect is only for Redux DevTools debugging) - -We can mix and match shorthand and longhand: - -```js -const customReducers = { - incrementByTwo: leafState => leafState + 2, - decrementBySumOf: { - argsToPayload: (first, second) => first + second, - reducer: (leafState, { payload }) => leafState - payload - } -} -``` - -## Example 1: custom action creator with no arguments - -Let's start with the shape of our app state. - -```js -import { createStore } from 'redux' -import reduxLeaves from 'reduxLeaves' - -const initialState = { - foo: 3, - bar: 4 -} -``` - -Suppose we want to implement a custom action: -- `double`: doubles the value of state at a leaf - -To do this, we need to define some custom reducer logic to pass to `reduxLeaves`: - -```js -const customReducers = { - square: leafState => leafState ** 2 // ES6 exponentiation -} -``` -We then pass this into `reduxLeaves`: -```js -const [reducer, actions] = reduxLeaves(initialState, customReducers) -const store = createStore(reducer) -``` -And now we can access the `square` action creator through the `create.custom` API: -```js -console.log(typeof actions.foo.create.custom.square) // function -console.log(typeof actions.bar.create.custom.square) // function -``` -Dispatching to the store triggers our custom reducer logic: -```js -store.dispatch(actions.foo.create.custom.square()) -console.log(store.getState().foo) // 9 - -store.dispatch(actions.bar.create.custom.square()) -console.log(store.getState().bar) // 16 -``` - -## Example 2: custom action creator using `payload` and `wholeState` - -When we define custom reducer logic to pass to `reduxLeaves`, by default the custom action creators accept one argument, which becomes the action payload. - -```js -import { createStore } from 'redux' -import reduxLeaves from 'reduxLeaves' - -const initialState = { - foo: 2, - bar: [2, 4, 6, 8, 10] -} -``` - -Suppose we want to implement two custom actions: -- `exponentiate`: raises the value of state at a leaf to an exponent received as an argument -- `remove`: removes values from the value of state at a leaf based on a value elsewhere, as indicated by an argument - -```js -const customReducers = { - exponentiate: (leafState, { payload }) => leafState ** payload, - remove: (leafState, { payload }, wholeState) => leafState.filter(e => e != wholeState[payload]) -} - -const [reducer, actions] = reduxLeaves(initialState, customReducers) -const store = createStore(reducer) - -// Testing that the action creators take only the first argument to be the payload: - -const expWithOneArg = actions.foo.create.custom.exponentiate(2) -const expWithTwoArgs = actions.foo.create.custom.exponentiate(3, 4) - -console.log(expWithOneArg.payload) // 2 -console.log(expWithTwoArgs.payload) // 3 (4 has been discarded) - -store.dispatch(expWithTwoArgs) -console.log(store.getState().foo) // 8 - -store.dispatch(actions.barr.create.custom.remove("foo")) -console.log(store.getState().bar) // [2, 4, 6, 10] <- state.foo, 8, removed -``` - -## Example 3: more detailed customisation with `argsToPayload` and `type` - -We can achieve greater customisation of our actions using the [object longhand](#object-longhand) for our `customReducers`. - -Suppose we want to implement a custom `remove` action creator such that it takes an arbitrary number of arguments and, when dispatched, removes all of them from the leaf state. - -Let's assume that we also want this to be flagged up in a very obvious way, in Redux DevTools, by giving it some (unsightly) action type, such as `!!! HEY THERE, I DID A THING !!!`. - -```js -import { createStore } from 'redux' -import reduxLeaves from 'reduxLeaves' - -const initialState = { - foo: [2, 4, 6, 8, 10] -} -const customReducers = { - remove: { - argsToPayload: (...values) => values, - reducer: (leafState, { payload }) => leafState.filter(e => !payload.includes(e)) - type: '!!! HEY THERE, I DID A THING !!!' - } -} - -const [reducer, actions] = reduxLeaves(initialState, customReducers) -const store = createStore(reducer) -``` - -Here, instead of passing in `remove` as a function, we have passed it in as an object with the following properties: - -- `argsToPayload`: this function receives all the arguments passed to the action creator, and its return value becomes the action `payload`; -- `reducer`: the reducer logic, invoked with arguments `leafState`, `{ payload }` and `wholeState` as before. -- `type`: the string constant for Redux DevTools to display. *This doesn't affect the reducer behaviour at all.* - -```js -const removeWithOneArg = actions.foo.create.custom.remove(4) -const removeWithTwoArgs = actions.foo.create.custom.remove(4, 8) - -console.log(removeWithOneArg.payload) // [4] -console.log(removeWithTwoArgs.payload) // [4, 8] - -console.log(removeWithTwoArgs.type) // !!! HEY THERE, I DID A THING !!! - -store.dispatch(removeWithTwoArgs) -console.log(store.getState().foo) // [2, 6, 10] -``` \ No newline at end of file diff --git a/docs/customReducers.spec.js b/docs/customReducers.spec.js deleted file mode 100644 index 8ecc5c3f..00000000 --- a/docs/customReducers.spec.js +++ /dev/null @@ -1,176 +0,0 @@ -import _ from 'lodash'; -import { createStore } from "redux"; -import reduxLeaves from '../src'; - -describe("API: reduxLeaves(initialState, [customReducers = {}])", () => { - - describe("Example 1: custom action creator with no arguments", () => { - describe("GIVEN initialState and customReducers", () => { - const initialState = { - foo: 3, - bar: 4 - } - - const customReducers = { - square: leafState => leafState ** 2 - } - - describe("WHEN we pass initialState and customReducers to reduxLeaves", () => { - const [reducer, actions] = reduxLeaves(initialState, customReducers) - let store - - beforeEach(() => store = createStore(reducer)) - - test("THEN store initialises with initialState", () => { - expect(store.getState()).toEqual(initialState) - }) - - test("AND create.custom.square is defined for actions.foo and actions.bar", () => { - expect(typeof actions.foo.create.custom.square).toBe("function") - expect(typeof actions.bar.create.custom.square).toBe("function") - }) - - describe("AND we dispatch actions.foo.create.custom.square()", () => { - beforeEach(() => { - store.dispatch(actions.foo.create.custom.square()) - }) - - test("THEN foo has squared, but not bar", () => { - expect(store.getState()).toEqual({ foo: 9, bar: 4 }) - }) - - describe("AND we dispatch actions.bar.create.custom.square()", () => { - beforeEach(() => { - store.dispatch(actions.bar.create.custom.square()) - }) - - test("THEN bar has also squared now", () => { - expect(store.getState()).toEqual({ foo: 9, bar: 16 }) - }) - }) - }) - }) - }) - }) - - describe("Example 2: custom action creator using payload and wholeState", () => { - describe("GIVEN initialState and customReducers", () => { - const initialState = { - foo: 2, - bar: [2, 4, 6, 8, 10] - } - - const customReducers = { - exponentiate: (leafState, { payload }) => leafState ** payload, - remove: (leafState, { payload }, wholeState) => leafState.filter(e => e != wholeState[payload]) - } - - describe("WHEN we pass initialState and customReducers to reduxLeaves", () => { - const [reducer, actions] = reduxLeaves(initialState, customReducers) - let store - - beforeEach(() => store = createStore(reducer)) - - test("THEN store initialises with initialState", () => { - expect(store.getState()).toEqual(initialState) - }) - - test("AND create.custom.exponentiate is defined for actions.foo", () => { - expect(typeof actions.foo.create.custom.exponentiate).toBe("function") - }) - - test("AND create.custom is defined for actions.bar", () => { - expect(typeof actions.bar.create.custom.remove).toBe("function") - }) - - describe("AND we pass arguments to custom.exponentiate before dispatching", () => { - const expWithOneArg = actions.foo.create.custom.exponentiate(2) - const expWithTwoArgs = actions.foo.create.custom.exponentiate(3, 4) - - beforeEach(() => { - store.dispatch(expWithTwoArgs) - }) - - test("THEN custom.exponentiate sets payload to be the first argument", () => { - expect(expWithOneArg.payload).toBe(2) - expect(expWithTwoArgs.payload).toBe(3) - }) - - test("AND the store state updates as expected", () => { - expect(store.getState()).toEqual({ ...initialState, foo: 8 }) - }) - - describe("AND we pass an argument to custom.remove before dispatching", () => { - const removeUsingFoo = actions.bar.create.custom.remove("foo") - - beforeEach(() => { - store.dispatch(removeUsingFoo) - }) - - test("THEN custom.remove sets payload to be the first argument", () => { - expect(removeUsingFoo.payload).toEqual("foo") - }) - - test("AND the store state updates as expected", () => { - expect(store.getState()).toEqual({ foo: 8, bar: [2, 4, 6, 10] }) - }) - }) - }) - }) - }) - }) - - describe("Example 3: more detailed customisation with argsToPayload", () => { - describe("GIVEN initialState and customReducers", () => { - const initialState = { - foo: [2, 4, 6, 8, 10] - } - - const customReducers = { - remove: { - argsToPayload: (...values) => values, - reducer: (leafState, { payload }) => leafState.filter(e => !payload.includes(e)), - type: '!!! HEY THERE, I DID A THING !!!' - } - } - - describe("WHEN we pass initialState and customReducers to reduxLeaves", () => { - const [reducer, actions] = reduxLeaves(initialState, customReducers) - let store - - beforeEach(() => store = createStore(reducer)) - - test("THEN store initialises with initialState", () => { - expect(store.getState()).toEqual(initialState) - }) - - test("AND create.custom.remove is defined for actions.foo", () => { - expect(typeof actions.foo.create.custom.remove).toBe("function") - }) - - describe("AND we pass arguments to custom.remove before dispatching", () => { - const removeWithOneArg = actions.foo.create.custom.remove(4) - const removeWithTwoArgs = actions.foo.create.custom.remove(4, 8) - - beforeEach(() => { - store.dispatch(removeWithTwoArgs) - }) - - test("THEN custom.remove sets payload to be the first argument", () => { - expect(removeWithOneArg.payload).toEqual([4]) - expect(removeWithTwoArgs.payload).toEqual([4, 8]) - }) - - test("AND actions have the passed in type", () => { - expect(removeWithOneArg.type).toBe('!!! HEY THERE, I DID A THING !!!') - expect(removeWithTwoArgs.type).toBe('!!! HEY THERE, I DID A THING !!!') - }) - - test("AND the store state updates as expected", () => { - expect(store.getState().foo).toEqual([2, 6, 10]) - }) - }) - }) - }) - }) -}) \ No newline at end of file diff --git a/docs/intro/README.md b/docs/intro/README.md index 9a1a0cee..05859474 100644 --- a/docs/intro/README.md +++ b/docs/intro/README.md @@ -10,7 +10,7 @@ The guiding philosophy of Redux-Leaves is *"write once, reduce anywhere"*. This page explains more about the motivation of Redux-Leaves and how its design philosophy is put into practice. -**Just want to see some code? Check out the [30 second demo](demo.md).** +> **Just want to see some code? Check out the [30 second demo](demo.md) or [Code Sandbox](https://codesandbox.io/s/reduxleaves-iwc4f).** ## Motivation @@ -18,7 +18,7 @@ This page explains more about the motivation of Redux-Leaves and how its design Redux is great, but some developers complain about the boilerplate being [tedious, cumbersome and convoluted](https://medium.com/@Charles_Stover/no-boilerplate-global-state-management-in-react-41e905944eb7). -**Redux-Leaves aims to make Redux easier to learn *and* quicker to scale**. +> **Redux-Leaves aims to make Redux easier to learn *and* quicker to scale**. ### How? @@ -33,7 +33,7 @@ Achieving this can feel like it requires a lot of boilerplate in: ... for *every single slice of state*. -**What if we could write reducer logic and have it available *throughout our state tree?*** +> **What if we could write reducer logic and have it available *throughout our state tree?*** ### What? diff --git a/docs/leafReducers.md b/docs/leafReducers.md index ba5b8044..92e3d5d9 100644 --- a/docs/leafReducers.md +++ b/docs/leafReducers.md @@ -40,11 +40,11 @@ Using the configuration object longhand allows greater customisation, through ad The list of configuration keys that can be provided are below: -| Key | Value | Description | Optional? | +| Key | Value (type) | Description | Optional? | | --- | --- | --- | --- | | [`reducer`](#reducer) | function | Updates the leaf's state | | | [`argsToPayload`](#argstopayload) | function | Converts action creator arguments to an action payload | Optional | -| [`actionType`](#actiontype) | string \| function | A string constant, or a function that returns a string, that becomes the action's `type` property | Optional | +| [`actionType`](#actiontype) | string / function | A string constant, or a function that returns a string, that becomes the action's `type` property | Optional | ### `reducer` *(function)*: Updates the leaf's state. diff --git a/website/i18n/en.json b/website/i18n/en.json index 3c086327..9b111caf 100644 --- a/website/i18n/en.json +++ b/website/i18n/en.json @@ -27,15 +27,15 @@ }, "create/defaults": { "title": "Default Action Creators", - "sidebar_label": "Default action creators" + "sidebar_label": "Universal" }, "create/creators": { "title": "Action Creators", - "sidebar_label": "Action creators" + "sidebar_label": "Actions" }, "create/type-specific": { "title": "Type-Specific Action Creators", - "sidebar_label": "Type-specific creators" + "sidebar_label": "Type-specific" }, "creator-keys": { "title": "Creator Keys", diff --git a/website/pages/en/index.js b/website/pages/en/index.js index c8f45a45..edfe7688 100644 --- a/website/pages/en/index.js +++ b/website/pages/en/index.js @@ -66,7 +66,7 @@ class HomeSplash extends React.Component { - + From 6036da145ae527e36348a6dee504162ad72f4936 Mon Sep 17 00:00:00 2001 From: Richard Ng Date: Sat, 18 May 2019 09:41:32 +0100 Subject: [PATCH 4/4] update some language stuff --- website/i18n/en.json | 4 ---- 1 file changed, 4 deletions(-) diff --git a/website/i18n/en.json b/website/i18n/en.json index 9b111caf..08f24255 100644 --- a/website/i18n/en.json +++ b/website/i18n/en.json @@ -41,10 +41,6 @@ "title": "Creator Keys", "sidebar_label": "Creator keys" }, - "custom-reducers": { - "title": "Advanced Usage", - "sidebar_label": "customReducers" - }, "intro/demo": { "title": "30 Second Demo", "sidebar_label": "30 second demo"