Skip to content
This repository was archived by the owner on Sep 16, 2020. It is now read-only.

Commit cc02844

Browse files
igorkamyshevsergeysova
authored andcommitted
feat: add random generating namespace (#22)
BREAKING CHANGE
1 parent ce0f719 commit cc02844

File tree

4 files changed

+35
-13
lines changed

4 files changed

+35
-13
lines changed

package-lock.json

Lines changed: 6 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
],
4242
"homepage": "https://github.com/sergeysova/redux-symbiote#readme",
4343
"dependencies": {
44+
"nanoid": "^2.0.1",
4445
"symbiote-symbol": "^1.1.0"
4546
},
4647
"devDependencies": {

src/index.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
const symbioteSymbols = require('symbiote-symbol')
2+
const nanoid = require('nanoid')
23

34

45
module.exports = {
@@ -11,7 +12,7 @@ module.exports = {
1112
* @param {defaultOptions | string} namespaceOptions
1213
* @returns {{ actions: {}, reducer: Function }}
1314
*/
14-
function createSymbiote(initialState, actionsConfig, namespaceOptions = '') {
15+
function createSymbiote(initialState, actionsConfig, namespaceOptions = nanoid()) {
1516
const builder = new SymbioteBuilder({
1617
state: initialState,
1718
options: createOptions(namespaceOptions),

test/index.js

Lines changed: 26 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -61,16 +61,25 @@ test('simple actions returns type and payload', (t) => {
6161
foo: (arg) => ({ arg }),
6262
})
6363

64-
t.deepEqual(actions.foo(1), { type: 'foo', payload: 1, 'symbiote-payload': [1] })
64+
const action = actions.foo(1)
65+
66+
t.is(action.payload, 1)
67+
t.deepEqual(action['symbiote-payload'], [1])
68+
t.true(action.type.endsWith('foo'))
6569
})
6670

6771
test('actions with state returns type and payload', (t) => {
6872
const { actions } = createSymbiote({}, {
6973
bar: (arg) => (state) => ({ arg, state }),
7074
})
7175

72-
t.deepEqual(actions.bar(1), { type: 'bar', payload: 1, 'symbiote-payload': [1] })
73-
t.is(actions.bar.toString(), 'bar', '.toString() return correct type')
76+
const action = actions.bar(1)
77+
78+
t.is(action.payload, 1)
79+
t.deepEqual(action['symbiote-payload'], [1])
80+
t.true(action.type.endsWith('bar'))
81+
82+
t.true(actions.bar.toString().endsWith('bar'), '.toString() return correct type')
7483
})
7584

7685
test('nested actions returns type and payload', (t) => {
@@ -80,8 +89,13 @@ test('nested actions returns type and payload', (t) => {
8089
},
8190
})
8291

83-
t.deepEqual(actions.bar.foo(1), { type: 'bar/foo', payload: 1, 'symbiote-payload': [1] })
84-
t.is(actions.bar.foo.toString(), 'bar/foo', '.toString() return correct type')
92+
const action = actions.bar.foo(1)
93+
94+
t.true(action.type.endsWith('bar/foo'))
95+
t.is(action.payload, 1)
96+
t.deepEqual(action['symbiote-payload'], [1])
97+
98+
t.true(actions.bar.foo.toString().endsWith('bar/foo'), '.toString() return correct type')
8599
})
86100

87101
test('nested actions with state returns type and payload', (t) => {
@@ -91,8 +105,13 @@ test('nested actions with state returns type and payload', (t) => {
91105
},
92106
})
93107

94-
t.deepEqual(actions.foo.bar(1), { type: 'foo/bar', payload: 1, 'symbiote-payload': [1] })
95-
t.is(actions.foo.bar.toString(), 'foo/bar', '.toString() return correct type')
108+
const action = actions.foo.bar(1)
109+
110+
t.true(action.type.endsWith('foo/bar'))
111+
t.is(action.payload, 1)
112+
t.deepEqual(action['symbiote-payload'], [1])
113+
114+
t.true(actions.foo.bar.toString().endsWith('foo/bar'), '.toString() return correct type')
96115
})
97116

98117
test('reducer return action resul', (t) => {

0 commit comments

Comments
 (0)