diff options
author | Samy Pessé <samypesse@gmail.com> | 2016-09-05 11:59:40 +0200 |
---|---|---|
committer | Samy Pessé <samypesse@gmail.com> | 2016-09-05 11:59:40 +0200 |
commit | 0e74c9bad5b184528880d499485e1154c000b1b5 (patch) | |
tree | 6628dc4ab27d6273727d6470dfcf99b11e8cdda1 /packages/gitbook-core/src/actions/components.js | |
parent | d7e415b0b396639b7e5c64d61f47569b40ced053 (diff) | |
download | gitbook-0e74c9bad5b184528880d499485e1154c000b1b5.zip gitbook-0e74c9bad5b184528880d499485e1154c000b1b5.tar.gz gitbook-0e74c9bad5b184528880d499485e1154c000b1b5.tar.bz2 |
Add action to register a component
Diffstat (limited to 'packages/gitbook-core/src/actions/components.js')
-rw-r--r-- | packages/gitbook-core/src/actions/components.js | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/packages/gitbook-core/src/actions/components.js b/packages/gitbook-core/src/actions/components.js new file mode 100644 index 0000000..89b0c9e --- /dev/null +++ b/packages/gitbook-core/src/actions/components.js @@ -0,0 +1,37 @@ +const ACTION_TYPES = require('./TYPES'); + +/** + * Find all components matching a descriptor + * @param {List<ComponentDescriptor>} state + * @param {String} matching.role + */ +function findMatchingComponents(state, matching) { + return state + .filter(({descriptor}) => { + if (matching.role && matching.role === descriptor.role) { + return false; + } + + return true; + }) + .map(component => component.Component); +} + +/** + * Register a new component + * @param {React.Class} Component + * @param {Descriptor} descriptor + * @return {Action} + */ +function registerComponent(Component, descriptor) { + return { + type: ACTION_TYPES.REGISTER_COMPONENT, + Component, + descriptor + }; +} + +module.exports = { + findMatchingComponents, + registerComponent +}; |