-
Notifications
You must be signed in to change notification settings - Fork 135
Expand file tree
/
Copy pathutil.js
More file actions
26 lines (22 loc) · 763 Bytes
/
util.js
File metadata and controls
26 lines (22 loc) · 763 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
// Bind an object/factory of actions to the store and wrap them.
export function mapActions(actions, store) {
if (typeof actions==='function') actions = actions(store);
const mapped = {};
for (let i in actions) mapped[i] = store.action(actions[i]);
return mapped;
}
// select('foo,bar') creates a function of the form: ({ foo, bar }) => ({ foo, bar })
export function select(properties) {
if (typeof properties==='string') properties = properties.split(/\s*,\s*/);
return state => {
const selected = {};
let i = properties.length;
while (i-- > 0) selected[properties[i]] = state[properties[i]];
return selected;
};
}
// Lighter Object.assign stand-in
export function assign(obj, props) {
for (let i in props) obj[i] = props[i];
return obj;
}