@financial-times/x-interaction
Advanced tools
Comparing version 0.0.3 to 0.0.4
@@ -263,2 +263,16 @@ const { h } = require('@financial-times/x-engine'); | ||
}); | ||
it('should get default state from second argument', async () => { | ||
const Base = () => null; | ||
const Wrapped = withActions({}, { | ||
foo: 5 | ||
})(Base); | ||
const target = mount(<Wrapped />); | ||
expect( | ||
target.find(Base).prop('foo') | ||
).toBe(5); | ||
}); | ||
}); | ||
@@ -265,0 +279,0 @@ |
@@ -243,4 +243,4 @@ 'use strict'; | ||
const withActions = getActions => Component => { | ||
const _wraps = { getActions, Component }; | ||
const withActions = (getActions, getDefaultState = {}) => Component => { | ||
const _wraps = { getActions, getDefaultState, Component }; | ||
@@ -252,4 +252,9 @@ // if the component we're wrapping is already wrapped, we don't want | ||
const wrappedGetActions = Component._wraps.getActions; | ||
const wrappedGetDefaultState = Component._wraps.getDefaultState; | ||
Component = Component._wraps.Component; | ||
getActions = initialState => Object.assign(invoke(wrappedGetActions, initialState), invoke(_wraps.getActions, initialState)); | ||
getDefaultState = initialState => Object.assign(invoke(wrappedGetDefaultState, initialState), invoke(_wraps.getDefaultState, initialState)); | ||
} | ||
@@ -264,2 +269,3 @@ | ||
const actions = invoke(getActions, initialState); | ||
const defaultState = invoke(getDefaultState, initialState); | ||
@@ -269,3 +275,3 @@ return xEngine.h(Interaction, { | ||
Component, | ||
initialState, | ||
initialState: Object.assign({}, defaultState, initialState), | ||
actionsRef, | ||
@@ -272,0 +278,0 @@ serialiser, |
@@ -405,4 +405,5 @@ 'use strict'; | ||
var withActions = function withActions(getActions) { | ||
var getDefaultState = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; | ||
return function (Component) { | ||
var _wraps = { getActions: getActions, Component: Component }; | ||
var _wraps = { getActions: getActions, getDefaultState: getDefaultState, Component: Component }; | ||
@@ -414,6 +415,13 @@ // if the component we're wrapping is already wrapped, we don't want | ||
var wrappedGetActions = Component._wraps.getActions; | ||
var wrappedGetDefaultState = Component._wraps.getDefaultState; | ||
Component = Component._wraps.Component; | ||
getActions = function getActions(initialState) { | ||
return Object.assign(invoke(wrappedGetActions, initialState), invoke(_wraps.getActions, initialState)); | ||
}; | ||
getDefaultState = function getDefaultState(initialState) { | ||
return Object.assign(invoke(wrappedGetDefaultState, initialState), invoke(_wraps.getDefaultState, initialState)); | ||
}; | ||
} | ||
@@ -428,2 +436,3 @@ | ||
var actions = invoke(getActions, initialState); | ||
var defaultState = invoke(getDefaultState, initialState); | ||
@@ -433,3 +442,3 @@ return xEngine.h(Interaction, { | ||
Component: Component, | ||
initialState: initialState, | ||
initialState: Object.assign({}, defaultState, initialState), | ||
actionsRef: actionsRef, | ||
@@ -436,0 +445,0 @@ serialiser: serialiser, |
@@ -237,4 +237,4 @@ import { h, Component, render } from '@financial-times/x-engine'; | ||
const withActions = getActions => Component$$1 => { | ||
const _wraps = { getActions, Component: Component$$1 }; | ||
const withActions = (getActions, getDefaultState = {}) => Component$$1 => { | ||
const _wraps = { getActions, getDefaultState, Component: Component$$1 }; | ||
@@ -246,4 +246,9 @@ // if the component we're wrapping is already wrapped, we don't want | ||
const wrappedGetActions = Component$$1._wraps.getActions; | ||
const wrappedGetDefaultState = Component$$1._wraps.getDefaultState; | ||
Component$$1 = Component$$1._wraps.Component; | ||
getActions = initialState => Object.assign(invoke(wrappedGetActions, initialState), invoke(_wraps.getActions, initialState)); | ||
getDefaultState = initialState => Object.assign(invoke(wrappedGetDefaultState, initialState), invoke(_wraps.getDefaultState, initialState)); | ||
} | ||
@@ -258,2 +263,3 @@ | ||
const actions = invoke(getActions, initialState); | ||
const defaultState = invoke(getDefaultState, initialState); | ||
@@ -263,3 +269,3 @@ return h(Interaction, { | ||
Component: Component$$1, | ||
initialState, | ||
initialState: Object.assign({}, defaultState, initialState), | ||
actionsRef, | ||
@@ -266,0 +272,0 @@ serialiser, |
{ | ||
"name": "@financial-times/x-interaction", | ||
"version": "0.0.3", | ||
"version": "0.0.4", | ||
"description": "This module enables you to write x-dash components that respond to events and change their own data.", | ||
@@ -5,0 +5,0 @@ "main": "dist/Interaction.cjs.js", |
@@ -14,4 +14,4 @@ import { h } from '@financial-times/x-engine'; | ||
export const withActions = (getActions) => (Component) => { | ||
const _wraps = { getActions, Component }; | ||
export const withActions = (getActions, getDefaultState = {}) => (Component) => { | ||
const _wraps = { getActions, getDefaultState, Component }; | ||
@@ -23,3 +23,6 @@ // if the component we're wrapping is already wrapped, we don't want | ||
const wrappedGetActions = Component._wraps.getActions; | ||
const wrappedGetDefaultState = Component._wraps.getDefaultState; | ||
Component = Component._wraps.Component; | ||
getActions = initialState => Object.assign( | ||
@@ -29,2 +32,7 @@ invoke(wrappedGetActions, initialState), | ||
); | ||
getDefaultState = initialState => Object.assign( | ||
invoke(wrappedGetDefaultState, initialState), | ||
invoke(_wraps.getDefaultState, initialState) | ||
); | ||
} | ||
@@ -39,2 +47,3 @@ | ||
const actions = invoke(getActions, initialState); | ||
const defaultState = invoke(getDefaultState, initialState); | ||
@@ -44,3 +53,3 @@ return <Interaction {...{ | ||
Component, | ||
initialState, | ||
initialState: Object.assign({}, defaultState, initialState), | ||
actionsRef, | ||
@@ -47,0 +56,0 @@ serialiser, |
58945
1307