File tree Expand file tree Collapse file tree 5 files changed +89
-0
lines changed Expand file tree Collapse file tree 5 files changed +89
-0
lines changed Original file line number Diff line number Diff line change
1
+ language : node_js
2
+ node_js :
3
+ - " 8"
4
+ - " 6"
5
+ notifications :
6
+ email : false
Original file line number Diff line number Diff line change
1
+ # @bufferapp/keywrapper
2
+
3
+ A quick way to wrap your Redux actions in a namespace.
4
+
5
+ When dealing with larger Redux applications, this can help avoid generic
6
+ action names from causing side effects. This will return an object with
7
+ namespaced string constants given a string namespace and an object. See
8
+ usage examples below for more info.
9
+
10
+ ## Install
11
+
12
+ ```
13
+ npm install @bufferapp/keywrapper
14
+ ```
15
+
16
+ ## Usage
17
+
18
+ ```
19
+ import keyWrapper from '@bufferapp/keywrapper'
20
+
21
+ const actions = keyWrapper('QUEUE', {
22
+ POST_DELETE: 0,
23
+ POST_SHARE_NOW: 0
24
+ })
25
+
26
+ console.log(actions)
27
+ /*
28
+ {
29
+ POST_DELETE: 'QUEUE__POST_DELETE',
30
+ POST_SHARE_NOW: 'QUEUE__POST_SHARE_NOW',
31
+ }
32
+ */
33
+ ```
34
+
35
+ ## License
36
+
37
+ MIT
Original file line number Diff line number Diff line change
1
+ module . exports = function keyWrapper ( namespace , actions ) {
2
+ return Object . keys ( actions )
3
+ . reduce ( ( o , action ) => {
4
+ o [ action ] = `${ namespace } __${ action } `
5
+ return o
6
+ } , { } )
7
+ }
Original file line number Diff line number Diff line change
1
+ const assert = require ( 'assert' )
2
+ const keyWrapper = require ( './index' )
3
+
4
+ const actionObject = {
5
+ CLICK_BUTTON : 0 ,
6
+ ADDITEM : 0
7
+ }
8
+
9
+ const wrappedOne = keyWrapper ( 'ONE' , actionObject )
10
+
11
+ assert . equal ( wrappedOne . CLICK_BUTTON , 'ONE__CLICK_BUTTON' )
12
+ assert . equal ( wrappedOne . ADDITEM , 'ONE__ADDITEM' )
13
+
14
+ console . log ( 'Tests passed!' )
Original file line number Diff line number Diff line change
1
+ {
2
+ "name" : " @bufferapp/keywrapper" ,
3
+ "version" : " 0.1.0" ,
4
+ "description" : " Wrap up your Redux Actions in a namespace bow" ,
5
+ "main" : " index.js" ,
6
+ "scripts" : {
7
+ "test" : " node index.test.js"
8
+ },
9
+ "repository" : {
10
+ "type" : " git" ,
11
+ "url" : " git+https://github.com/bufferapp/buffer-js-keywrapper.git"
12
+ },
13
+ "keywords" : [
14
+ " redux"
15
+ ],
16
+ "author" : " Dan Farrelly <daniel.j.farrelly@gmail.com> (http://danfarrelly.nyc)" ,
17
+ "license" : " MIT" ,
18
+ "bugs" : {
19
+ "url" : " https://github.com/bufferapp/buffer-js-keywrapper/issues"
20
+ },
21
+ "files" : [
22
+ " index.js"
23
+ ],
24
+ "homepage" : " https://github.com/bufferapp/buffer-js-keywrapper#readme"
25
+ }
You can’t perform that action at this time.
0 commit comments