Comparing version 2.2.0-beta.6 to 2.2.0-beta.7
@@ -46,5 +46,4 @@ 'use strict'; | ||
return; | ||
} // already connected to all, skip checking everything individually | ||
} | ||
if (logic.connections[otherLogic.pathString]) { | ||
@@ -61,18 +60,2 @@ return; | ||
/* | ||
Copy the connect'ed logic stores' selectors and actions into this object | ||
input.connect = { | ||
logic: [farmSceneLogic], | ||
values: [farmSceneLogic, ['chicken']], | ||
actions: [farmSceneLogic, ['setChicken']] | ||
} | ||
... converts to: | ||
logic.connections = { 'scenes.farm': farmSceneLogic } | ||
logic.actionCreators = { setChicken: (id) => ({ type: 'set chicken (farm)', payload: { id } } }) } | ||
logic.selectors = { chicken: (state) => state.scenes.farm } | ||
*/ | ||
function createConnect(logic, input) { | ||
@@ -185,5 +168,3 @@ if (!input.connect) { | ||
} | ||
} // input: [ logic1, [ 'a', 'b as c' ], logic2, [ 'c', 'd' ] ] | ||
// logic: [ [logic1, 'a', 'a'], [logic1, 'b', 'c'], [logic2, 'c', 'c'], [logic2, 'd', 'd'] ] | ||
} | ||
function deconstructMapping(mapping) { | ||
@@ -215,11 +196,2 @@ if (mapping.length % 2 === 1) { | ||
/* | ||
Convert any requested constants to objects that can be destructured | ||
input.constants = ['SOMETHING', 'CONSTANT_NAME'] | ||
... converts to: | ||
logic.constants = { SOMETHING: 'SOMETHING', CONSTANT_NAME: 'CONSTANT_NAME' } | ||
*/ | ||
function createConstants(logic, input) { | ||
@@ -232,4 +204,3 @@ if (!input.constants) { | ||
Object.assign(logic.constants, constants); | ||
} // convert ['A', 'B'] ==> { 'A': 'A', 'B': 'B' } | ||
} | ||
function convertConstants(c) { | ||
@@ -276,15 +247,3 @@ if (Array.isArray(c)) { | ||
}; | ||
/* | ||
input.actions = ({ path, constants }) => ({ | ||
setDuckId: (duckId) => ({ duckId }) | ||
}) | ||
... converts to: | ||
logic.actionCreators == { | ||
setDuckId: (duckId) => ({ type: 'set duck (...)', payload: { duckId } }), | ||
} | ||
*/ | ||
function createActionCreators(logic, input) { | ||
@@ -308,20 +267,6 @@ if (!input.actions) { | ||
/* | ||
logic.actionCreators == { | ||
setDuckId: (duckId) => ({ type: 'set duck (...)', payload: { duckId } }), | ||
} | ||
... converts to: | ||
logic.actions = { | ||
setDuckId: (duckId) => dispatch(logic.actionCreators.setDuckId(duckId)) | ||
} | ||
*/ | ||
function createActions(logic, input) { | ||
Object.keys(logic.actionCreators).forEach(function (key) { | ||
var actionCreator = logic.actionCreators[key]; | ||
var type = actionCreator.toString(); // we must add the action on the run heap, otherwise if in a listener we dispatch an action, | ||
// which causes a react re-render, all logic.build() calls in the react component will be | ||
// connected to the listener | ||
var type = actionCreator.toString(); | ||
@@ -337,5 +282,2 @@ logic.actions[key] = function () { | ||
try { | ||
// TODO: This will return "undefined" in the next major/breaking version of kea. | ||
// The TypeScript types already say "void" for actions. | ||
// ... even if this still returns the dispatched "actionCreator" output | ||
return getContext().store.dispatch(builtAction); | ||
@@ -356,16 +298,2 @@ } finally { | ||
/* | ||
input.defaults = ({ actions, selectors }) => (state, props) => ({ | ||
key1: selectors.something(state).key1, | ||
key2: selectors.other(state, props).key2 | ||
}) | ||
... converts to: | ||
logic.defaults = { | ||
key1: 10, | ||
key2: 20 | ||
} | ||
*/ | ||
function createDefaults(logic, input) { | ||
@@ -430,21 +358,2 @@ var _getContext = getContext(), | ||
/* | ||
input.reducers = ({ actions, path, constants }) => ({ | ||
duckId: [10, PropTypes.number, { persist: true }, { | ||
[actions.setDuckId]: (_, payload) => payload.duckId | ||
}] | ||
}) | ||
... converts to: | ||
logic.reducers = { | ||
duckId: function () {} | ||
}, | ||
logic.propTypes = { | ||
duckId: PropTypes.number | ||
}, | ||
logic.defaults = { | ||
duckId: 10 | ||
} | ||
*/ | ||
function createReducers(logic, input) { | ||
@@ -467,3 +376,2 @@ if (!input.reducers) { | ||
if (Array.isArray(object)) { | ||
// s = [ value, (type), (options), reducer ] | ||
initialValue = object[0]; | ||
@@ -481,7 +389,5 @@ reducer = object[object.length - 1]; | ||
throw new Error("[KEA] Logic \"" + logic.pathString + "\" reducer \"" + key + "\" is set to unsupported value"); | ||
} // if we have a previously provided default value, use it | ||
} | ||
if (typeof logic.defaults[key] === 'undefined') { | ||
// there is a root default selector. use it and try to get the key, fallback to initialValue | ||
if (typeof logic.defaults['*'] === 'function') { | ||
@@ -563,5 +469,4 @@ logic.defaults[key] = function (state, props) { | ||
}; | ||
} // create reducer function from such an object { [action]: (state, payload) => state } | ||
} | ||
function createMappingReducer(mapping, defaultValue, key, logic) { | ||
@@ -769,8 +674,6 @@ if (Object.keys(mapping).length === 0) { | ||
for (var i = 0; i < path.length; i++) { | ||
var pathPart = path[i]; // last part of the path, so [..., pathPart] = path | ||
var pathPart = path[i]; | ||
if (i === path.length - 1) { | ||
// there's already something here! | ||
if (pointer[pathPart]) { | ||
// if we're in the root level in the tree and it's an empty object | ||
if (i === 0 && typeof pointer[pathPart] === 'object' && Object.keys(pointer[pathPart]).length === 0) ; else if (typeof pointer[pathPart] !== 'function') { | ||
@@ -827,3 +730,3 @@ console.error("[KEA] Can not add reducer to \"" + path.join('.') + "\". There is something in the way:", pointer[pathPart]); | ||
var pointer = tree; | ||
var detached = false; // ['scenes', 'sceneName', 'page', 'key'] | ||
var detached = false; | ||
@@ -905,7 +808,3 @@ for (var i = path.length - 2; i >= 0; i--) { | ||
} | ||
} // We are using our own function for the tree nodes instead of redux's combineReducers beacause this way we will not | ||
// get the constant 'Unexpected key "1" found in previous state received by the reducer' warnings when unmounting. | ||
// Instead we'll simply discard the keys we don't need. | ||
// Please note that logic reducers are still built with redux's combineReducers. | ||
} | ||
function combineKeaReducers(reducers) { | ||
@@ -959,10 +858,2 @@ var reducerKeys = Object.keys(reducers); | ||
var emptyObject = {}; | ||
/* | ||
logic.reducers = { duckId: function () {} } | ||
... converts to: | ||
logic.reducer = combineReducers(logic.reducers) | ||
*/ | ||
function createReducer(logic, input) { | ||
@@ -982,10 +873,2 @@ if (!input.reducers) { | ||
/* | ||
logic.reducers = { duckId: function () {} } | ||
... converts to | ||
logic.selectors = { duckId: (state) => state.scenes.ducks.duckId } // memoized via reselect | ||
*/ | ||
function createReducerSelectors(logic, input) { | ||
@@ -1009,4 +892,3 @@ if (!logic.reducer) { | ||
}); | ||
} // input: ['scenes', 'something', 'other'], state | ||
// output: state.scenes.something.other | ||
} | ||
@@ -1019,19 +901,2 @@ function pathSelector(path, state) { | ||
/* | ||
input.selectors = ({ selectors }) => ({ | ||
duckAndChicken: [ | ||
() => [selectors.duckId, selectors.chickenId], | ||
(duckId, chickenId) => duckId + chickenId, | ||
PropType.number | ||
], | ||
}) | ||
... converts to | ||
logic.selector = state => state.scenes.farm // memoized via reselect | ||
logic.selectors = { | ||
duckAndChicken: state => logic.selector(state).duckAndChicken // memoized via reselect | ||
} | ||
*/ | ||
function createSelectors(logic, input) { | ||
@@ -1043,4 +908,3 @@ if (!input.selectors) { | ||
var selectorInputs = typeof input.selectors === 'function' ? input.selectors(logic) : input.selectors; | ||
var selectorKeys = Object.keys(selectorInputs); // small cache so the order would not count | ||
var selectorKeys = Object.keys(selectorInputs); | ||
var builtSelectors = {}; | ||
@@ -1175,14 +1039,2 @@ selectorKeys.forEach(function (key) { | ||
/* usage: | ||
kea({ | ||
listeners: ({ actions, values, store, sharedListeners }) => ({ | ||
[actions.openUrl]: ({ url }, breakpoint, action) => { actions.urlOpened(url) }, | ||
[LOCATION_CHANGE]: [ | ||
(payload, breakpoint, action) => { store.dispatch(...) }, | ||
sharedListeners.otherListeForTheSameAction | ||
] | ||
}) | ||
}) | ||
*/ | ||
var LISTENERS_BREAKPOINT = 'kea-listeners breakpoint broke'; | ||
@@ -1376,3 +1228,3 @@ var isBreakpoint = function isBreakpoint(error) { | ||
removeListenersByPathString(logic.pathString, logic.listeners); // trigger all breakpoints | ||
removeListenersByPathString(logic.pathString, logic.listeners); | ||
@@ -1430,4 +1282,3 @@ if (logic.cache.listenerBreakpointCounter) { | ||
var reduxDevToolsCompose = typeof window !== 'undefined' && window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__ ? window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__ : redux.compose; // this must be a function as we need new objects every time | ||
// otherwise it could happen that the "middleware" array gets mutated on the default | ||
var reduxDevToolsCompose = typeof window !== 'undefined' && window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__ ? window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__ : redux.compose; | ||
@@ -1461,20 +1312,15 @@ var defaultOptions = function defaultOptions() { | ||
return; | ||
} // clone options | ||
} | ||
var options = Object.assign({}, defaultOptions(), opts); | ||
context.reducers.redux = Object.assign({}, options.reducers); | ||
runPlugins('beforeReduxStore', options); | ||
var options = Object.assign({}, defaultOptions(), opts); // clone redux reducers | ||
context.reducers.redux = Object.assign({}, options.reducers); // run pre-hooks | ||
runPlugins('beforeReduxStore', options); // combine middleware into the first enhancer | ||
if (options.middleware.length > 0) { | ||
options.enhancers = [redux.applyMiddleware.apply(void 0, options.middleware)].concat(options.enhancers); | ||
} // use a special compose function? | ||
} | ||
var composeEnchancer = options.compose || redux.compose; | ||
var finalCreateStore = composeEnchancer.apply(void 0, options.enhancers)(redux.createStore); | ||
var composeEnchancer = options.compose || redux.compose; // create the store creator | ||
var finalCreateStore = composeEnchancer.apply(void 0, options.enhancers)(redux.createStore); // if we are whitelisting paths | ||
if (options.paths && options.paths.length > 0) { | ||
@@ -1488,8 +1334,6 @@ context.reducers.whitelist = []; | ||
initRootReducerTree('kea'); | ||
} // create store | ||
} | ||
var store = finalCreateStore(createCombinedReducer(), Object.assign({}, options.preloadedState)); | ||
context.store = store; // run post-hooks | ||
context.store = store; | ||
runPlugins('afterReduxStore', options, store); | ||
@@ -1496,0 +1340,0 @@ return store; |
@@ -5,6 +5,7 @@ export * from './types'; | ||
export { resetContext, openContext, closeContext, getContext, getPluginContext, setPluginContext } from './context'; | ||
export { keaReducer, getStore, ATTACH_REDUCER, DETACH_REDUCER } from './store'; | ||
export { getStore } from './store/store'; | ||
export { keaReducer, ATTACH_REDUCER, DETACH_REDUCER } from './store/reducer'; | ||
export { activatePlugin } from './plugins'; | ||
export { createAction } from './core/shared/actions'; | ||
export { addConnection } from './core/shared/connect'; | ||
export { isBreakpoint } from './listeners'; | ||
export { isBreakpoint } from './listeners/index'; |
@@ -42,5 +42,4 @@ import { createSelector } from 'reselect'; | ||
return; | ||
} // already connected to all, skip checking everything individually | ||
} | ||
if (logic.connections[otherLogic.pathString]) { | ||
@@ -57,18 +56,2 @@ return; | ||
/* | ||
Copy the connect'ed logic stores' selectors and actions into this object | ||
input.connect = { | ||
logic: [farmSceneLogic], | ||
values: [farmSceneLogic, ['chicken']], | ||
actions: [farmSceneLogic, ['setChicken']] | ||
} | ||
... converts to: | ||
logic.connections = { 'scenes.farm': farmSceneLogic } | ||
logic.actionCreators = { setChicken: (id) => ({ type: 'set chicken (farm)', payload: { id } } }) } | ||
logic.selectors = { chicken: (state) => state.scenes.farm } | ||
*/ | ||
function createConnect(logic, input) { | ||
@@ -181,5 +164,3 @@ if (!input.connect) { | ||
} | ||
} // input: [ logic1, [ 'a', 'b as c' ], logic2, [ 'c', 'd' ] ] | ||
// logic: [ [logic1, 'a', 'a'], [logic1, 'b', 'c'], [logic2, 'c', 'c'], [logic2, 'd', 'd'] ] | ||
} | ||
function deconstructMapping(mapping) { | ||
@@ -211,11 +192,2 @@ if (mapping.length % 2 === 1) { | ||
/* | ||
Convert any requested constants to objects that can be destructured | ||
input.constants = ['SOMETHING', 'CONSTANT_NAME'] | ||
... converts to: | ||
logic.constants = { SOMETHING: 'SOMETHING', CONSTANT_NAME: 'CONSTANT_NAME' } | ||
*/ | ||
function createConstants(logic, input) { | ||
@@ -228,4 +200,3 @@ if (!input.constants) { | ||
Object.assign(logic.constants, constants); | ||
} // convert ['A', 'B'] ==> { 'A': 'A', 'B': 'B' } | ||
} | ||
function convertConstants(c) { | ||
@@ -272,15 +243,3 @@ if (Array.isArray(c)) { | ||
}; | ||
/* | ||
input.actions = ({ path, constants }) => ({ | ||
setDuckId: (duckId) => ({ duckId }) | ||
}) | ||
... converts to: | ||
logic.actionCreators == { | ||
setDuckId: (duckId) => ({ type: 'set duck (...)', payload: { duckId } }), | ||
} | ||
*/ | ||
function createActionCreators(logic, input) { | ||
@@ -304,20 +263,6 @@ if (!input.actions) { | ||
/* | ||
logic.actionCreators == { | ||
setDuckId: (duckId) => ({ type: 'set duck (...)', payload: { duckId } }), | ||
} | ||
... converts to: | ||
logic.actions = { | ||
setDuckId: (duckId) => dispatch(logic.actionCreators.setDuckId(duckId)) | ||
} | ||
*/ | ||
function createActions(logic, input) { | ||
Object.keys(logic.actionCreators).forEach(function (key) { | ||
var actionCreator = logic.actionCreators[key]; | ||
var type = actionCreator.toString(); // we must add the action on the run heap, otherwise if in a listener we dispatch an action, | ||
// which causes a react re-render, all logic.build() calls in the react component will be | ||
// connected to the listener | ||
var type = actionCreator.toString(); | ||
@@ -333,5 +278,2 @@ logic.actions[key] = function () { | ||
try { | ||
// TODO: This will return "undefined" in the next major/breaking version of kea. | ||
// The TypeScript types already say "void" for actions. | ||
// ... even if this still returns the dispatched "actionCreator" output | ||
return getContext().store.dispatch(builtAction); | ||
@@ -352,16 +294,2 @@ } finally { | ||
/* | ||
input.defaults = ({ actions, selectors }) => (state, props) => ({ | ||
key1: selectors.something(state).key1, | ||
key2: selectors.other(state, props).key2 | ||
}) | ||
... converts to: | ||
logic.defaults = { | ||
key1: 10, | ||
key2: 20 | ||
} | ||
*/ | ||
function createDefaults(logic, input) { | ||
@@ -426,21 +354,2 @@ var _getContext = getContext(), | ||
/* | ||
input.reducers = ({ actions, path, constants }) => ({ | ||
duckId: [10, PropTypes.number, { persist: true }, { | ||
[actions.setDuckId]: (_, payload) => payload.duckId | ||
}] | ||
}) | ||
... converts to: | ||
logic.reducers = { | ||
duckId: function () {} | ||
}, | ||
logic.propTypes = { | ||
duckId: PropTypes.number | ||
}, | ||
logic.defaults = { | ||
duckId: 10 | ||
} | ||
*/ | ||
function createReducers(logic, input) { | ||
@@ -463,3 +372,2 @@ if (!input.reducers) { | ||
if (Array.isArray(object)) { | ||
// s = [ value, (type), (options), reducer ] | ||
initialValue = object[0]; | ||
@@ -477,7 +385,5 @@ reducer = object[object.length - 1]; | ||
throw new Error("[KEA] Logic \"" + logic.pathString + "\" reducer \"" + key + "\" is set to unsupported value"); | ||
} // if we have a previously provided default value, use it | ||
} | ||
if (typeof logic.defaults[key] === 'undefined') { | ||
// there is a root default selector. use it and try to get the key, fallback to initialValue | ||
if (typeof logic.defaults['*'] === 'function') { | ||
@@ -559,5 +465,4 @@ logic.defaults[key] = function (state, props) { | ||
}; | ||
} // create reducer function from such an object { [action]: (state, payload) => state } | ||
} | ||
function createMappingReducer(mapping, defaultValue, key, logic) { | ||
@@ -765,8 +670,6 @@ if (Object.keys(mapping).length === 0) { | ||
for (var i = 0; i < path.length; i++) { | ||
var pathPart = path[i]; // last part of the path, so [..., pathPart] = path | ||
var pathPart = path[i]; | ||
if (i === path.length - 1) { | ||
// there's already something here! | ||
if (pointer[pathPart]) { | ||
// if we're in the root level in the tree and it's an empty object | ||
if (i === 0 && typeof pointer[pathPart] === 'object' && Object.keys(pointer[pathPart]).length === 0) ; else if (typeof pointer[pathPart] !== 'function') { | ||
@@ -823,3 +726,3 @@ console.error("[KEA] Can not add reducer to \"" + path.join('.') + "\". There is something in the way:", pointer[pathPart]); | ||
var pointer = tree; | ||
var detached = false; // ['scenes', 'sceneName', 'page', 'key'] | ||
var detached = false; | ||
@@ -901,7 +804,3 @@ for (var i = path.length - 2; i >= 0; i--) { | ||
} | ||
} // We are using our own function for the tree nodes instead of redux's combineReducers beacause this way we will not | ||
// get the constant 'Unexpected key "1" found in previous state received by the reducer' warnings when unmounting. | ||
// Instead we'll simply discard the keys we don't need. | ||
// Please note that logic reducers are still built with redux's combineReducers. | ||
} | ||
function combineKeaReducers(reducers) { | ||
@@ -955,10 +854,2 @@ var reducerKeys = Object.keys(reducers); | ||
var emptyObject = {}; | ||
/* | ||
logic.reducers = { duckId: function () {} } | ||
... converts to: | ||
logic.reducer = combineReducers(logic.reducers) | ||
*/ | ||
function createReducer(logic, input) { | ||
@@ -978,10 +869,2 @@ if (!input.reducers) { | ||
/* | ||
logic.reducers = { duckId: function () {} } | ||
... converts to | ||
logic.selectors = { duckId: (state) => state.scenes.ducks.duckId } // memoized via reselect | ||
*/ | ||
function createReducerSelectors(logic, input) { | ||
@@ -1005,4 +888,3 @@ if (!logic.reducer) { | ||
}); | ||
} // input: ['scenes', 'something', 'other'], state | ||
// output: state.scenes.something.other | ||
} | ||
@@ -1015,19 +897,2 @@ function pathSelector(path, state) { | ||
/* | ||
input.selectors = ({ selectors }) => ({ | ||
duckAndChicken: [ | ||
() => [selectors.duckId, selectors.chickenId], | ||
(duckId, chickenId) => duckId + chickenId, | ||
PropType.number | ||
], | ||
}) | ||
... converts to | ||
logic.selector = state => state.scenes.farm // memoized via reselect | ||
logic.selectors = { | ||
duckAndChicken: state => logic.selector(state).duckAndChicken // memoized via reselect | ||
} | ||
*/ | ||
function createSelectors(logic, input) { | ||
@@ -1039,4 +904,3 @@ if (!input.selectors) { | ||
var selectorInputs = typeof input.selectors === 'function' ? input.selectors(logic) : input.selectors; | ||
var selectorKeys = Object.keys(selectorInputs); // small cache so the order would not count | ||
var selectorKeys = Object.keys(selectorInputs); | ||
var builtSelectors = {}; | ||
@@ -1171,14 +1035,2 @@ selectorKeys.forEach(function (key) { | ||
/* usage: | ||
kea({ | ||
listeners: ({ actions, values, store, sharedListeners }) => ({ | ||
[actions.openUrl]: ({ url }, breakpoint, action) => { actions.urlOpened(url) }, | ||
[LOCATION_CHANGE]: [ | ||
(payload, breakpoint, action) => { store.dispatch(...) }, | ||
sharedListeners.otherListeForTheSameAction | ||
] | ||
}) | ||
}) | ||
*/ | ||
var LISTENERS_BREAKPOINT = 'kea-listeners breakpoint broke'; | ||
@@ -1372,3 +1224,3 @@ var isBreakpoint = function isBreakpoint(error) { | ||
removeListenersByPathString(logic.pathString, logic.listeners); // trigger all breakpoints | ||
removeListenersByPathString(logic.pathString, logic.listeners); | ||
@@ -1426,4 +1278,3 @@ if (logic.cache.listenerBreakpointCounter) { | ||
var reduxDevToolsCompose = typeof window !== 'undefined' && window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__ ? window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__ : compose; // this must be a function as we need new objects every time | ||
// otherwise it could happen that the "middleware" array gets mutated on the default | ||
var reduxDevToolsCompose = typeof window !== 'undefined' && window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__ ? window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__ : compose; | ||
@@ -1457,20 +1308,15 @@ var defaultOptions = function defaultOptions() { | ||
return; | ||
} // clone options | ||
} | ||
var options = Object.assign({}, defaultOptions(), opts); | ||
context.reducers.redux = Object.assign({}, options.reducers); | ||
runPlugins('beforeReduxStore', options); | ||
var options = Object.assign({}, defaultOptions(), opts); // clone redux reducers | ||
context.reducers.redux = Object.assign({}, options.reducers); // run pre-hooks | ||
runPlugins('beforeReduxStore', options); // combine middleware into the first enhancer | ||
if (options.middleware.length > 0) { | ||
options.enhancers = [applyMiddleware.apply(void 0, options.middleware)].concat(options.enhancers); | ||
} // use a special compose function? | ||
} | ||
var composeEnchancer = options.compose || compose; | ||
var finalCreateStore = composeEnchancer.apply(void 0, options.enhancers)(createStore); | ||
var composeEnchancer = options.compose || compose; // create the store creator | ||
var finalCreateStore = composeEnchancer.apply(void 0, options.enhancers)(createStore); // if we are whitelisting paths | ||
if (options.paths && options.paths.length > 0) { | ||
@@ -1484,8 +1330,6 @@ context.reducers.whitelist = []; | ||
initRootReducerTree('kea'); | ||
} // create store | ||
} | ||
var store = finalCreateStore(createCombinedReducer(), Object.assign({}, options.preloadedState)); | ||
context.store = store; // run post-hooks | ||
context.store = store; | ||
runPlugins('afterReduxStore', options, store); | ||
@@ -1492,0 +1336,0 @@ return store; |
import { LogicInput, Props } from '../types'; | ||
export declare function getPathForInput(input: LogicInput, props: Props): string[]; | ||
export declare function getPathForInput(input: LogicInput, props: Props): import("../types").PathType; | ||
export declare function getPathStringForInput(input: LogicInput, props: Props): string; |
@@ -1,5 +0,5 @@ | ||
import { Plugin, PluginEvents } from '../types'; | ||
export declare function activatePlugin(pluginToActivate: Plugin | (() => Plugin)): void; | ||
import { KeaPlugin, PluginEvents } from '../types'; | ||
export declare function activatePlugin(pluginToActivate: KeaPlugin | (() => KeaPlugin)): void; | ||
declare type PluginParameters<T> = T extends (...args: infer P) => any ? P : never; | ||
export declare function runPlugins<T extends keyof PluginEvents, E extends PluginParameters<PluginEvents[T]>>(key: T, ...args: E): void; | ||
export {}; |
@@ -21,5 +21,7 @@ import { Reducer, Store, Action as ReduxAction } from 'redux'; | ||
defaults: Record<string, any>; | ||
listeners: Record<string, any>; | ||
path: PathType; | ||
pathString: string; | ||
props: Props; | ||
propTypes: Record<string, any>; | ||
reducers: any; | ||
@@ -49,5 +51,5 @@ reducerOptions: Record<string, any>; | ||
(component: AnyComponent): FunctionComponent; | ||
(props: LogicType['props'] | undefined): BuiltLogic; | ||
(props: LogicType['props'] extends Props ? any : LogicType['props'] | undefined): BuiltLogic; | ||
wrap: (Component: AnyComponent) => KeaComponent; | ||
build: (props?: LogicType['props'], autoConnectInListener?: boolean) => BuiltLogic; | ||
build: (props?: LogicType['props'] extends Props ? any : LogicType['props'], autoConnectInListener?: boolean) => BuiltLogic; | ||
mount: (callback?: any) => () => void; | ||
@@ -75,7 +77,6 @@ extend: (extendedInput: LogicInput) => LogicWrapper; | ||
declare type BreakPointFunction = (() => void) & ((ms: number) => Promise<void>); | ||
declare type ListenerDefinitions<LogicType extends Logic> = { | ||
[K in keyof LogicType['actionCreators']]?: ((payload: ReturnType<LogicType['actionCreators'][K]>['payload'], breakpoint: BreakPointFunction, action: ReturnType<LogicType['actionCreators'][K]>, previousState: any) => void | Promise<void>) | (() => void | Promise<void>); | ||
} | { | ||
[K in keyof LogicType['__keaTypeGenInternalReducerActions']]?: ((payload: ReturnType<LogicType['__keaTypeGenInternalReducerActions'][K]>['payload'], breakpoint: BreakPointFunction, action: ReturnType<LogicType['__keaTypeGenInternalReducerActions'][K]>, previousState: any) => void | Promise<void>) | (() => void | Promise<void>); | ||
declare type ListenerDefinitionsForRecord<A extends Record<string, (...args: any) => any>> = { | ||
[K in keyof A]?: ((payload: ReturnType<A[K]>['payload'], breakpoint: BreakPointFunction, action: ReturnType<A[K]>, previousState: any) => void | Promise<void>) | (() => void | Promise<void>); | ||
}; | ||
declare type ListenerDefinitions<LogicType extends Logic> = ListenerDefinitionsForRecord<LogicType['actionCreators']> | ListenerDefinitionsForRecord<LogicType['__keaTypeGenInternalReducerActions']>; | ||
declare type WindowValuesDefinitions<LogicType extends Logic> = Record<string, (window: Window) => any>; | ||
@@ -127,8 +128,3 @@ declare type LoaderFunctions<LogicType extends Logic, ReducerReturnType> = { | ||
actions: Actions; | ||
cache: Record<string, unknown>; | ||
constants: Record<string, string>; | ||
defaults: Values; | ||
path: PathType; | ||
pathString: string; | ||
reducerOptions: Record<string, unknown>; | ||
reducer: (state: Values, action: () => any, fullState: any) => Values; | ||
@@ -198,3 +194,3 @@ reducers: { | ||
}; | ||
export interface Plugin { | ||
export interface KeaPlugin { | ||
name: string; | ||
@@ -211,3 +207,3 @@ defaults?: () => Record<string, any>; | ||
plugins: { | ||
activated: Plugin[]; | ||
activated: KeaPlugin[]; | ||
buildOrder: string[]; | ||
@@ -214,0 +210,0 @@ buildSteps: Record<string, BuildStep[]>; |
{ | ||
"name": "kea", | ||
"version": "2.2.0-beta.6", | ||
"version": "2.2.0-beta.7", | ||
"description": "Smart front-end architecture", | ||
"author": "Marius Andra", | ||
"license": "MIT", | ||
"types": "lib/index.d.ts", | ||
"types": "lib/kea.d.ts", | ||
"main": "lib/index.cjs.js", | ||
@@ -25,3 +25,3 @@ "module": "lib/index.esm.js", | ||
"scripts": { | ||
"build": "npm run clean && npm run compile", | ||
"build": "yarn run clean && yarn run compile", | ||
"clean": "rimraf lib/*", | ||
@@ -134,2 +134,3 @@ "compile": "npm run compile:rollup", | ||
"rollup-plugin-commonjs": "^10.1.0", | ||
"rollup-plugin-dts": "^1.4.9", | ||
"rollup-plugin-node-resolve": "^5.2.0", | ||
@@ -136,0 +137,0 @@ "rollup-plugin-typescript2": "^0.27.1", |
import corePlugin from '../core' | ||
import listenersPlugin from '../listeners' | ||
import listenersPlugin from '../listeners/index' | ||
import { activatePlugin, runPlugins } from '../plugins' | ||
import { getStore } from '../store' | ||
import { getStore } from '../store/store' | ||
import { Context, ContextOptions } from '../types' | ||
@@ -6,0 +6,0 @@ |
@@ -9,3 +9,4 @@ export * from './types' | ||
export { resetContext, openContext, closeContext, getContext, getPluginContext, setPluginContext } from './context' | ||
export { keaReducer, getStore, ATTACH_REDUCER, DETACH_REDUCER } from './store' | ||
export { getStore } from './store/store' | ||
export { keaReducer, ATTACH_REDUCER, DETACH_REDUCER } from './store/reducer' | ||
export { activatePlugin } from './plugins' | ||
@@ -15,5 +16,5 @@ | ||
export { addConnection } from './core/shared/connect' | ||
export { isBreakpoint } from './listeners' | ||
export { isBreakpoint } from './listeners/index' | ||
// this will create a default context | ||
resetContext() |
@@ -8,3 +8,3 @@ import { runPlugins } from '../plugins' | ||
import { Logic, LogicWrapper, Props, LogicInput, BuiltLogicAdditions, BuiltLogic } from '../types' | ||
import { Logic, LogicWrapper, Props, LogicInput, BuiltLogicAdditions, BuiltLogic, PathType } from '../types' | ||
@@ -37,3 +37,3 @@ // Converts `input` into `logic` by running all build steps in succession | ||
key: string | undefined | ||
path: string[] | ||
path: PathType | ||
props: Props | ||
@@ -92,3 +92,3 @@ wrapper: LogicWrapper | ||
inputs: LogicInput[] | ||
path: string[] | ||
path: PathType | ||
key: string | undefined | ||
@@ -95,0 +95,0 @@ props: Props |
import { getContext } from '../context' | ||
import { Plugin, PluginEvents } from '../types' | ||
import { KeaPlugin, PluginEvents } from '../types' | ||
/* | ||
@@ -105,3 +105,3 @@ plugins = [ | ||
export function activatePlugin(pluginToActivate: Plugin | (() => Plugin)): void { | ||
export function activatePlugin(pluginToActivate: KeaPlugin | (() => KeaPlugin)): void { | ||
const plugin = typeof pluginToActivate === 'function' ? pluginToActivate() : pluginToActivate | ||
@@ -108,0 +108,0 @@ |
@@ -23,5 +23,7 @@ import { Reducer, Store, Action as ReduxAction } from 'redux' | ||
defaults: Record<string, any> | ||
listeners: Record<string, any> | ||
path: PathType | ||
pathString: string | ||
props: Props | ||
propTypes: Record<string, any> | ||
reducers: any | ||
@@ -54,5 +56,8 @@ reducerOptions: Record<string, any> | ||
(component: AnyComponent): FunctionComponent | ||
(props: LogicType['props'] | undefined): BuiltLogic | ||
(props: LogicType['props'] extends Props ? any : LogicType['props'] | undefined): BuiltLogic | ||
wrap: (Component: AnyComponent) => KeaComponent | ||
build: (props?: LogicType['props'], autoConnectInListener?: boolean) => BuiltLogic | ||
build: ( | ||
props?: LogicType['props'] extends Props ? any : LogicType['props'], | ||
autoConnectInListener?: boolean, | ||
) => BuiltLogic | ||
mount: (callback?: any) => () => void | ||
@@ -121,23 +126,16 @@ extend: (extendedInput: LogicInput) => LogicWrapper | ||
type ListenerDefinitionsForRecord<A extends Record<string, (...args: any) => any>> = { | ||
[K in keyof A]?: | ||
| (( | ||
payload: ReturnType<A[K]>['payload'], | ||
breakpoint: BreakPointFunction, | ||
action: ReturnType<A[K]>, | ||
previousState: any, | ||
) => void | Promise<void>) | ||
| (() => void | Promise<void>) | ||
} | ||
type ListenerDefinitions<LogicType extends Logic> = | ||
| { | ||
[K in keyof LogicType['actionCreators']]?: | ||
| (( | ||
payload: ReturnType<LogicType['actionCreators'][K]>['payload'], | ||
breakpoint: BreakPointFunction, | ||
action: ReturnType<LogicType['actionCreators'][K]>, | ||
previousState: any, | ||
) => void | Promise<void>) | ||
| (() => void | Promise<void>) | ||
} | ||
| { | ||
[K in keyof LogicType['__keaTypeGenInternalReducerActions']]?: | ||
| (( | ||
payload: ReturnType<LogicType['__keaTypeGenInternalReducerActions'][K]>['payload'], | ||
breakpoint: BreakPointFunction, | ||
action: ReturnType<LogicType['__keaTypeGenInternalReducerActions'][K]>, | ||
previousState: any, | ||
) => void | Promise<void>) | ||
| (() => void | Promise<void>) | ||
} | ||
| ListenerDefinitionsForRecord<LogicType['actionCreators']> | ||
| ListenerDefinitionsForRecord<LogicType['__keaTypeGenInternalReducerActions']> | ||
@@ -222,8 +220,3 @@ type WindowValuesDefinitions<LogicType extends Logic> = Record<string, (window: Window) => any> | ||
actions: Actions | ||
cache: Record<string, unknown> | ||
constants: Record<string, string> | ||
defaults: Values | ||
path: PathType | ||
pathString: string | ||
reducerOptions: Record<string, unknown> | ||
reducer: (state: Values, action: () => any, fullState: any) => Values | ||
@@ -304,3 +297,3 @@ reducers: { | ||
export interface Plugin { | ||
export interface KeaPlugin { | ||
name: string | ||
@@ -315,3 +308,3 @@ defaults?: () => Record<string, any> | ||
plugins: { | ||
activated: Plugin[] | ||
activated: KeaPlugin[] | ||
buildOrder: string[] | ||
@@ -318,0 +311,0 @@ buildSteps: Record<string, BuildStep[]> |
468638
98
64
13727