Comparing version 2.2.0-rc.3 to 2.2.0-rc.4
@@ -201,14 +201,26 @@ 'use strict'; | ||
} | ||
function convertConstants(c) { | ||
if (Array.isArray(c)) { | ||
var a = {}; | ||
function convertConstants(constants) { | ||
if (Array.isArray(constants)) { | ||
var response = {}; | ||
for (var i = 0; i < c.length; i++) { | ||
a[c[i]] = c[i]; | ||
for (var _iterator = constants, _isArray = Array.isArray(_iterator), _i = 0, _iterator = _isArray ? _iterator : _iterator[Symbol.iterator]();;) { | ||
var _ref; | ||
if (_isArray) { | ||
if (_i >= _iterator.length) break; | ||
_ref = _iterator[_i++]; | ||
} else { | ||
_i = _iterator.next(); | ||
if (_i.done) break; | ||
_ref = _i.value; | ||
} | ||
var value = _ref; | ||
response[value] = value; | ||
} | ||
return a; | ||
return response; | ||
} | ||
return c; | ||
return constants; | ||
} | ||
@@ -326,3 +338,3 @@ | ||
var part = _ref; | ||
defaults = defaults[part]; | ||
defaults = defaults[part.toString()]; | ||
@@ -429,3 +441,3 @@ if (typeof defaults !== 'object') { | ||
var funReducer = createFunctionReducer(cache.functions, logic.defaults[key]); | ||
var funReducer = createFunctionReducer(cache.functions, logic.defaults[key], key, logic); | ||
var mapReducer = createMappingReducer(cache.mapping, logic.defaults[key], key, logic); | ||
@@ -913,5 +925,6 @@ var newReducer = funReducer && mapReducer ? function (state, action, fullState) { | ||
}).length > 0) { | ||
var msg = "[KEA] Logic \"" + logic.pathString + "\", selector \"" + key + "\" has incorrect input: [" + args.map(function (a) { | ||
var argTypes = args.map(function (a) { | ||
return typeof a; | ||
}).join(', ') + "]."; | ||
}).join(', '); | ||
var msg = "[KEA] Logic \"" + logic.pathString + "\", selector \"" + key + "\" has incorrect input: [" + argTypes + "]."; | ||
throw new Error(msg); | ||
@@ -921,3 +934,3 @@ } | ||
builtSelectors[key] = reselect.createSelector.apply(void 0, args.concat([func])); | ||
builtSelectors[key] = reselect.createSelector(args, func); | ||
@@ -977,5 +990,5 @@ logic.selectors[key] = function (state, props) { | ||
oldEvent(); | ||
newEvent(); | ||
newEvent && newEvent(); | ||
}; | ||
} else { | ||
} else if (newEvent) { | ||
logic.events[key] = newEvent; | ||
@@ -1328,5 +1341,3 @@ } | ||
var getStoreState = function getStoreState() { | ||
var _getContext$store; | ||
return (_getContext$store = getContext().store) === null || _getContext$store === void 0 ? void 0 : _getContext$store.getState(); | ||
return getContext().store.getState(); | ||
}; | ||
@@ -1879,6 +1890,4 @@ function setContext(newContext) { | ||
return function () { | ||
var _unmount$current; | ||
isUnmounting[pathString.current] = true; | ||
(_unmount$current = unmount.current) === null || _unmount$current === void 0 ? void 0 : _unmount$current.call(unmount); | ||
unmount.current && unmount.current(); | ||
delete isUnmounting[pathString.current]; | ||
@@ -2087,5 +2096,3 @@ delete lastState[pathString.current]; | ||
return function () { | ||
var _unmount$current; | ||
return (_unmount$current = unmount.current) === null || _unmount$current === void 0 ? void 0 : _unmount$current.call(unmount); | ||
return unmount.current && unmount.current(); | ||
}; | ||
@@ -2092,0 +2099,0 @@ }, []); |
@@ -11,2 +11,4 @@ import { Store, Action, Reducer } from 'redux'; | ||
declare type EmptyProps = '___EMPTY_PROPS___'; | ||
declare type LogicEventType = 'beforeMount' | 'afterMount' | 'beforeUnmount' | 'afterUnmount'; | ||
declare type PartialRecord<K extends keyof any, T> = Partial<Record<K, T>>; | ||
interface Logic { | ||
@@ -35,8 +37,3 @@ key: any; | ||
values: Record<string, any>; | ||
events: { | ||
beforeMount?: () => void; | ||
afterMount?: () => void; | ||
beforeUnmount?: () => void; | ||
afterUnmount?: () => void; | ||
}; | ||
events: PartialRecord<LogicEventType, () => void>; | ||
__keaTypeGenInternalSelectorTypes: Record<string, (...args: any) => any>; | ||
@@ -75,3 +72,3 @@ __keaTypeGenInternalReducerActions: Record<string, (...args: any) => { | ||
declare type SelectorTuple = [] | [Selector] | [Selector, Selector] | [Selector, Selector, Selector] | [Selector, Selector, Selector, Selector] | [Selector, Selector, Selector, Selector, Selector] | [Selector, Selector, Selector, Selector, Selector, Selector] | [Selector, Selector, Selector, Selector, Selector, Selector, Selector] | [Selector, Selector, Selector, Selector, Selector, Selector, Selector, Selector] | [Selector, Selector, Selector, Selector, Selector, Selector, Selector, Selector, Selector] | [Selector, Selector, Selector, Selector, Selector, Selector, Selector, Selector, Selector, Selector] | [Selector, Selector, Selector, Selector, Selector, Selector, Selector, Selector, Selector, Selector, Selector]; | ||
declare type SelectorDefinition<Selectors, SelectorFunction extends any> = [(s: Selectors) => SelectorTuple, SelectorFunction]; | ||
declare type SelectorDefinition<Selectors, SelectorFunction extends any> = [(s: Selectors) => SelectorTuple, SelectorFunction] | [(s: Selectors) => SelectorTuple, SelectorFunction, any]; | ||
declare type SelectorDefinitions<LogicType extends Logic> = { | ||
@@ -102,3 +99,3 @@ [K in keyof LogicType['__keaTypeGenInternalSelectorTypes']]?: SelectorDefinition<LogicType['selectors'], LogicType['__keaTypeGenInternalSelectorTypes'][K]>; | ||
connect?: any; | ||
constants?: () => string[] | string[]; | ||
constants?: (logic: LogicType) => string[] | string[]; | ||
actions?: ActionDefinitions<LogicType> | ((logic: LogicType) => ActionDefinitions<LogicType>); | ||
@@ -109,14 +106,4 @@ reducers?: ReducerDefinitions<LogicType> | ((logic: LogicType) => ReducerDefinitions<LogicType>); | ||
sharedListeners?: SharedListenerDefinitions | ((logic: LogicType) => SharedListenerDefinitions); | ||
events?: { | ||
beforeMount?: (() => void) | (() => void)[]; | ||
afterMount?: (() => void) | (() => void)[]; | ||
beforeUnmount?: (() => void) | (() => void)[]; | ||
afterUnmount?: (() => void) | (() => void)[]; | ||
} | ((logic: LogicType) => { | ||
beforeMount?: (() => void) | (() => void)[]; | ||
afterMount?: (() => void) | (() => void)[]; | ||
beforeUnmount?: (() => void) | (() => void)[]; | ||
afterUnmount?: (() => void) | (() => void)[]; | ||
}); | ||
defaults?: any; | ||
events?: PartialRecord<LogicEventType, (() => void) | (() => void)[]> | ((logic: LogicType) => PartialRecord<LogicEventType, (() => void) | (() => void)[]>); | ||
defaults?: ((logic: LogicType) => (state: any, props: LogicType['props']) => Record<string, any>) | ((logic: LogicType) => Record<string, any>) | Record<string, any>; | ||
loaders?: LoaderDefinitions<LogicType> | ((logic: LogicType) => LoaderDefinitions<LogicType>); | ||
@@ -251,3 +238,3 @@ windowValues?: WindowValuesDefinitions<LogicType> | ((logic: LogicType) => WindowValuesDefinitions<LogicType>); | ||
type: 'action' | 'listener'; | ||
logic: BuiltLogic; | ||
logic: Logic; | ||
}[]; | ||
@@ -262,3 +249,3 @@ }; | ||
}; | ||
store?: Store; | ||
store: Store; | ||
options: InternalContextOptions; | ||
@@ -281,3 +268,3 @@ } | ||
declare function getPluginContext(name: string): Record<string, any>; | ||
declare function setPluginContext(name: string, pluginContext: object): void; | ||
declare function setPluginContext(name: string, pluginContext: Record<string, any>): void; | ||
@@ -301,3 +288,3 @@ declare function getStore(opts?: {}): any; | ||
declare function addConnection(logic: any, otherLogic: any): void; | ||
declare function addConnection(logic: Logic, otherLogic: Logic): void; | ||
@@ -309,2 +296,2 @@ declare function isBreakpoint(error: any): boolean; | ||
export { ATTACH_REDUCER, AnyComponent, BreakPointFunction, BuiltLogic, BuiltLogicAdditions, Context, ContextOptions, DETACH_REDUCER, EmptyProps, InternalContextOptions, KeaComponent, KeaPlugin, Logic, LogicInput, LogicWrapper, LogicWrapperAdditions, MakeLogicType, PathCreator, PathType, PluginEventArrays, PluginEvents, Props, RequiredPathCreator, Selector, activatePlugin, addConnection, closeContext, connect, createAction, getContext, getPluginContext, getStore, isBreakpoint, kea, keaReducer, openContext, resetContext, setPluginContext, useActions, useAllValues, useKea, useMountedLogic, useValues }; | ||
export { ATTACH_REDUCER, AnyComponent, BreakPointFunction, BuiltLogic, BuiltLogicAdditions, Context, ContextOptions, DETACH_REDUCER, EmptyProps, InternalContextOptions, KeaComponent, KeaPlugin, Logic, LogicEventType, LogicInput, LogicWrapper, LogicWrapperAdditions, MakeLogicType, PartialRecord, PathCreator, PathType, PluginEventArrays, PluginEvents, Props, RequiredPathCreator, Selector, activatePlugin, addConnection, closeContext, connect, createAction, getContext, getPluginContext, getStore, isBreakpoint, kea, keaReducer, openContext, resetContext, setPluginContext, useActions, useAllValues, useKea, useMountedLogic, useValues }; |
@@ -197,14 +197,26 @@ import { createSelector } from 'reselect'; | ||
} | ||
function convertConstants(c) { | ||
if (Array.isArray(c)) { | ||
var a = {}; | ||
function convertConstants(constants) { | ||
if (Array.isArray(constants)) { | ||
var response = {}; | ||
for (var i = 0; i < c.length; i++) { | ||
a[c[i]] = c[i]; | ||
for (var _iterator = constants, _isArray = Array.isArray(_iterator), _i = 0, _iterator = _isArray ? _iterator : _iterator[Symbol.iterator]();;) { | ||
var _ref; | ||
if (_isArray) { | ||
if (_i >= _iterator.length) break; | ||
_ref = _iterator[_i++]; | ||
} else { | ||
_i = _iterator.next(); | ||
if (_i.done) break; | ||
_ref = _i.value; | ||
} | ||
var value = _ref; | ||
response[value] = value; | ||
} | ||
return a; | ||
return response; | ||
} | ||
return c; | ||
return constants; | ||
} | ||
@@ -322,3 +334,3 @@ | ||
var part = _ref; | ||
defaults = defaults[part]; | ||
defaults = defaults[part.toString()]; | ||
@@ -425,3 +437,3 @@ if (typeof defaults !== 'object') { | ||
var funReducer = createFunctionReducer(cache.functions, logic.defaults[key]); | ||
var funReducer = createFunctionReducer(cache.functions, logic.defaults[key], key, logic); | ||
var mapReducer = createMappingReducer(cache.mapping, logic.defaults[key], key, logic); | ||
@@ -909,5 +921,6 @@ var newReducer = funReducer && mapReducer ? function (state, action, fullState) { | ||
}).length > 0) { | ||
var msg = "[KEA] Logic \"" + logic.pathString + "\", selector \"" + key + "\" has incorrect input: [" + args.map(function (a) { | ||
var argTypes = args.map(function (a) { | ||
return typeof a; | ||
}).join(', ') + "]."; | ||
}).join(', '); | ||
var msg = "[KEA] Logic \"" + logic.pathString + "\", selector \"" + key + "\" has incorrect input: [" + argTypes + "]."; | ||
throw new Error(msg); | ||
@@ -917,3 +930,3 @@ } | ||
builtSelectors[key] = createSelector.apply(void 0, args.concat([func])); | ||
builtSelectors[key] = createSelector(args, func); | ||
@@ -973,5 +986,5 @@ logic.selectors[key] = function (state, props) { | ||
oldEvent(); | ||
newEvent(); | ||
newEvent && newEvent(); | ||
}; | ||
} else { | ||
} else if (newEvent) { | ||
logic.events[key] = newEvent; | ||
@@ -1324,5 +1337,3 @@ } | ||
var getStoreState = function getStoreState() { | ||
var _getContext$store; | ||
return (_getContext$store = getContext().store) === null || _getContext$store === void 0 ? void 0 : _getContext$store.getState(); | ||
return getContext().store.getState(); | ||
}; | ||
@@ -1875,6 +1886,4 @@ function setContext(newContext) { | ||
return function () { | ||
var _unmount$current; | ||
isUnmounting[pathString.current] = true; | ||
(_unmount$current = unmount.current) === null || _unmount$current === void 0 ? void 0 : _unmount$current.call(unmount); | ||
unmount.current && unmount.current(); | ||
delete isUnmounting[pathString.current]; | ||
@@ -2083,5 +2092,3 @@ delete lastState[pathString.current]; | ||
return function () { | ||
var _unmount$current; | ||
return (_unmount$current = unmount.current) === null || _unmount$current === void 0 ? void 0 : _unmount$current.call(unmount); | ||
return unmount.current && unmount.current(); | ||
}; | ||
@@ -2088,0 +2095,0 @@ }, []); |
@@ -10,5 +10,5 @@ import { Context, ContextOptions } from '../types'; | ||
context: Context; | ||
returnValue: any; | ||
returnValue: unknown; | ||
}; | ||
export declare function getPluginContext(name: string): Record<string, any>; | ||
export declare function setPluginContext(name: string, pluginContext: object): void; | ||
export declare function setPluginContext(name: string, pluginContext: Record<string, any>): void; |
@@ -1,4 +0,15 @@ | ||
declare namespace _default { | ||
export const name: string; | ||
export function defaults(): { | ||
import { createConnect } from './steps/connect'; | ||
import { createConstants } from './steps/constants'; | ||
import { createActionCreators } from './steps/action-creators'; | ||
import { createActions } from './steps/actions'; | ||
import { createDefaults } from './steps/defaults'; | ||
import { createReducers } from './steps/reducers'; | ||
import { createReducer } from './steps/reducer'; | ||
import { createReducerSelectors } from './steps/reducer-selectors'; | ||
import { createSelectors } from './steps/selectors'; | ||
import { createValues } from './steps/values'; | ||
import { createEvents } from './steps/events'; | ||
declare const _default: { | ||
name: string; | ||
defaults: () => { | ||
cache: {}; | ||
@@ -21,16 +32,16 @@ connections: {}; | ||
}; | ||
export namespace buildSteps { | ||
export { createConnect as connect }; | ||
export { createConstants as constants }; | ||
export { createActionCreators as actionCreators }; | ||
export { createActions as actions }; | ||
export { createDefaults as defaults }; | ||
export { createReducers as reducers }; | ||
export { createReducer as reducer }; | ||
export { createReducerSelectors as reducerSelectors }; | ||
export { createSelectors as selectors }; | ||
export { createValues as values }; | ||
export { createEvents as events }; | ||
} | ||
} | ||
buildSteps: { | ||
connect: typeof createConnect; | ||
constants: typeof createConstants; | ||
actionCreators: typeof createActionCreators; | ||
actions: typeof createActions; | ||
defaults: typeof createDefaults; | ||
reducers: typeof createReducers; | ||
reducer: typeof createReducer; | ||
reducerSelectors: typeof createReducerSelectors; | ||
selectors: typeof createSelectors; | ||
values: typeof createValues; | ||
events: typeof createEvents; | ||
}; | ||
}; | ||
export default _default; |
@@ -1,1 +0,2 @@ | ||
export function addConnection(logic: any, otherLogic: any): void; | ||
import { Logic } from '../../types'; | ||
export declare function addConnection(logic: Logic, otherLogic: Logic): void; |
@@ -1,2 +0,3 @@ | ||
export function createActionCreators(logic: any, input: any): void; | ||
export function createActionType(key: any, pathString: any): string; | ||
import { Logic, LogicInput } from '../../types'; | ||
export declare function createActionCreators(logic: Logic, input: LogicInput): void; | ||
export declare function createActionType(key: string, pathString: string): string; |
@@ -1,1 +0,2 @@ | ||
export function createActions(logic: any, input: any): void; | ||
import { Logic, LogicInput } from '../../types'; | ||
export declare function createActions(logic: Logic, input: LogicInput): void; |
@@ -1,2 +0,3 @@ | ||
export function createConnect(logic: any, input: any): void; | ||
export function deconstructMapping(mapping: any): any[][]; | ||
import { Logic, LogicInput } from '../../types'; | ||
export declare function createConnect(logic: Logic, input: LogicInput): void; | ||
export declare function deconstructMapping(mapping: any): any[]; |
@@ -1,2 +0,3 @@ | ||
export function createConstants(logic: any, input: any): void; | ||
export default function convertConstants(c: any): any; | ||
import { Logic, LogicInput } from '../../types'; | ||
export declare function createConstants(logic: Logic, input: LogicInput): void; | ||
export default function convertConstants(constants: string[]): Record<string, string>; |
@@ -1,1 +0,2 @@ | ||
export function createDefaults(logic: any, input: any): void; | ||
import { Logic, LogicInput } from '../../types'; | ||
export declare function createDefaults(logic: Logic, input: LogicInput): void; |
@@ -1,1 +0,2 @@ | ||
export function createEvents(logic: any, input: any): void; | ||
import { Logic, LogicInput } from '../../types'; | ||
export declare function createEvents(logic: Logic, input: LogicInput): void; |
@@ -1,1 +0,2 @@ | ||
export function createReducerSelectors(logic: any, input: any): void; | ||
import { Logic, LogicInput } from '../../types'; | ||
export declare function createReducerSelectors(logic: Logic, input: LogicInput): void; |
@@ -1,1 +0,2 @@ | ||
export function createReducer(logic: any, input: any): void; | ||
import { Logic, LogicInput } from '../../types'; | ||
export declare function createReducer(logic: Logic, input: LogicInput): void; |
@@ -1,1 +0,2 @@ | ||
export function createReducers(logic: any, input: any): void; | ||
import { Logic, LogicInput } from '../../types'; | ||
export declare function createReducers(logic: Logic, input: LogicInput): void; |
@@ -1,1 +0,2 @@ | ||
export function createSelectors(logic: any, input: any): void; | ||
import { Logic, LogicInput } from '../../types'; | ||
export declare function createSelectors(logic: Logic, input: LogicInput): void; |
@@ -1,1 +0,2 @@ | ||
export function createValues(logic: any, input: any): void; | ||
import { Logic, LogicInput } from '../../types'; | ||
export declare function createValues(logic: Logic, input: LogicInput): void; |
@@ -10,2 +10,4 @@ import { Reducer, Store, Action as ReduxAction } from 'redux'; | ||
export declare type EmptyProps = '___EMPTY_PROPS___'; | ||
export declare type LogicEventType = 'beforeMount' | 'afterMount' | 'beforeUnmount' | 'afterUnmount'; | ||
export declare type PartialRecord<K extends keyof any, T> = Partial<Record<K, T>>; | ||
export interface Logic { | ||
@@ -34,8 +36,3 @@ key: any; | ||
values: Record<string, any>; | ||
events: { | ||
beforeMount?: () => void; | ||
afterMount?: () => void; | ||
beforeUnmount?: () => void; | ||
afterUnmount?: () => void; | ||
}; | ||
events: PartialRecord<LogicEventType, () => void>; | ||
__keaTypeGenInternalSelectorTypes: Record<string, (...args: any) => any>; | ||
@@ -74,3 +71,3 @@ __keaTypeGenInternalReducerActions: Record<string, (...args: any) => { | ||
declare type SelectorTuple = [] | [Selector] | [Selector, Selector] | [Selector, Selector, Selector] | [Selector, Selector, Selector, Selector] | [Selector, Selector, Selector, Selector, Selector] | [Selector, Selector, Selector, Selector, Selector, Selector] | [Selector, Selector, Selector, Selector, Selector, Selector, Selector] | [Selector, Selector, Selector, Selector, Selector, Selector, Selector, Selector] | [Selector, Selector, Selector, Selector, Selector, Selector, Selector, Selector, Selector] | [Selector, Selector, Selector, Selector, Selector, Selector, Selector, Selector, Selector, Selector] | [Selector, Selector, Selector, Selector, Selector, Selector, Selector, Selector, Selector, Selector, Selector]; | ||
declare type SelectorDefinition<Selectors, SelectorFunction extends any> = [(s: Selectors) => SelectorTuple, SelectorFunction]; | ||
declare type SelectorDefinition<Selectors, SelectorFunction extends any> = [(s: Selectors) => SelectorTuple, SelectorFunction] | [(s: Selectors) => SelectorTuple, SelectorFunction, any]; | ||
declare type SelectorDefinitions<LogicType extends Logic> = { | ||
@@ -101,3 +98,3 @@ [K in keyof LogicType['__keaTypeGenInternalSelectorTypes']]?: SelectorDefinition<LogicType['selectors'], LogicType['__keaTypeGenInternalSelectorTypes'][K]>; | ||
connect?: any; | ||
constants?: () => string[] | string[]; | ||
constants?: (logic: LogicType) => string[] | string[]; | ||
actions?: ActionDefinitions<LogicType> | ((logic: LogicType) => ActionDefinitions<LogicType>); | ||
@@ -108,14 +105,4 @@ reducers?: ReducerDefinitions<LogicType> | ((logic: LogicType) => ReducerDefinitions<LogicType>); | ||
sharedListeners?: SharedListenerDefinitions | ((logic: LogicType) => SharedListenerDefinitions); | ||
events?: { | ||
beforeMount?: (() => void) | (() => void)[]; | ||
afterMount?: (() => void) | (() => void)[]; | ||
beforeUnmount?: (() => void) | (() => void)[]; | ||
afterUnmount?: (() => void) | (() => void)[]; | ||
} | ((logic: LogicType) => { | ||
beforeMount?: (() => void) | (() => void)[]; | ||
afterMount?: (() => void) | (() => void)[]; | ||
beforeUnmount?: (() => void) | (() => void)[]; | ||
afterUnmount?: (() => void) | (() => void)[]; | ||
}); | ||
defaults?: any; | ||
events?: PartialRecord<LogicEventType, (() => void) | (() => void)[]> | ((logic: LogicType) => PartialRecord<LogicEventType, (() => void) | (() => void)[]>); | ||
defaults?: ((logic: LogicType) => (state: any, props: LogicType['props']) => Record<string, any>) | ((logic: LogicType) => Record<string, any>) | Record<string, any>; | ||
loaders?: LoaderDefinitions<LogicType> | ((logic: LogicType) => LoaderDefinitions<LogicType>); | ||
@@ -250,3 +237,3 @@ windowValues?: WindowValuesDefinitions<LogicType> | ((logic: LogicType) => WindowValuesDefinitions<LogicType>); | ||
type: 'action' | 'listener'; | ||
logic: BuiltLogic; | ||
logic: Logic; | ||
}[]; | ||
@@ -261,5 +248,5 @@ }; | ||
}; | ||
store?: Store; | ||
store: Store; | ||
options: InternalContextOptions; | ||
} | ||
export {}; |
{ | ||
"name": "kea", | ||
"version": "2.2.0-rc.3", | ||
"version": "2.2.0-rc.4", | ||
"description": "Smart front-end architecture", | ||
@@ -5,0 +5,0 @@ "author": "Marius Andra", |
@@ -6,16 +6,17 @@ import corePlugin from '../core/index' | ||
import { Context, ContextOptions } from '../types' | ||
import { Store } from 'redux' | ||
let context: Context | ||
export function getContext() { | ||
export function getContext(): Context { | ||
return context | ||
} | ||
export const getStoreState = () => getContext().store?.getState() | ||
export const getStoreState = () => getContext().store.getState() | ||
export function setContext(newContext: Context) { | ||
export function setContext(newContext: Context): void { | ||
context = newContext | ||
} | ||
export function openContext(options: ContextOptions = {}) { | ||
export function openContext(options: ContextOptions = {}): Context { | ||
if (context) { | ||
@@ -65,3 +66,3 @@ console.error('[KEA] overwriting already opened context. This may lead to errors.') | ||
store: undefined, | ||
store: (undefined as unknown) as Store, // will be redefined below | ||
__store: undefined, | ||
@@ -84,3 +85,3 @@ | ||
get: function get() { | ||
const store = (newContext as any)['__store'] | ||
const store: Store = (newContext as any)['__store'] | ||
if (!store && createStore) { | ||
@@ -115,3 +116,3 @@ return getStore(typeof createStore === 'object' ? createStore : {}) | ||
export function closeContext() { | ||
export function closeContext(): void { | ||
if (context) { | ||
@@ -124,3 +125,3 @@ runPlugins('beforeCloseContext', context) | ||
export function resetContext(options: ContextOptions = {}) { | ||
export function resetContext(options: ContextOptions = {}): Context { | ||
if (context) { | ||
@@ -133,3 +134,9 @@ closeContext() | ||
export function withContext(code: (context?: Context) => any, options = {}) { | ||
export function withContext( | ||
code: (context?: Context) => any, | ||
options = {}, | ||
): { | ||
context: Context | ||
returnValue: unknown | ||
} { | ||
const oldContext = context | ||
@@ -150,3 +157,3 @@ | ||
export function getPluginContext(name: string) { | ||
export function getPluginContext(name: string): Record<string, any> { | ||
const { plugins } = getContext() | ||
@@ -159,5 +166,5 @@ if (!plugins.contexts[name]) { | ||
export function setPluginContext(name: string, pluginContext: object) { | ||
export function setPluginContext(name: string, pluginContext: Record<string, any>): void { | ||
const { plugins } = getContext() | ||
plugins.contexts[name] = pluginContext | ||
} |
@@ -67,3 +67,3 @@ import { useMemo, useEffect, useRef } from 'react' | ||
useEffect(() => () => unmount.current?.(), []) | ||
useEffect(() => () => unmount.current && unmount.current(), []) | ||
} |
@@ -80,3 +80,3 @@ import * as React from 'react' | ||
isUnmounting[pathString.current] = true | ||
unmount.current?.() | ||
unmount.current && unmount.current() | ||
delete isUnmounting[pathString.current] | ||
@@ -83,0 +83,0 @@ delete lastState[pathString.current] |
@@ -12,2 +12,4 @@ import { Reducer, Store, Action as ReduxAction } from 'redux' | ||
export type EmptyProps = '___EMPTY_PROPS___' | ||
export type LogicEventType = 'beforeMount' | 'afterMount' | 'beforeUnmount' | 'afterUnmount' | ||
export type PartialRecord<K extends keyof any, T> = Partial<Record<K, T>> | ||
@@ -36,8 +38,3 @@ // logic base class | ||
values: Record<string, any> | ||
events: { | ||
beforeMount?: () => void | ||
afterMount?: () => void | ||
beforeUnmount?: () => void | ||
afterUnmount?: () => void | ||
} | ||
events: PartialRecord<LogicEventType, () => void> | ||
@@ -110,3 +107,5 @@ __keaTypeGenInternalSelectorTypes: Record<string, (...args: any) => any> | ||
type SelectorDefinition<Selectors, SelectorFunction extends any> = [(s: Selectors) => SelectorTuple, SelectorFunction] | ||
type SelectorDefinition<Selectors, SelectorFunction extends any> = | ||
| [(s: Selectors) => SelectorTuple, SelectorFunction] | ||
| [(s: Selectors) => SelectorTuple, SelectorFunction, any] | ||
@@ -171,3 +170,3 @@ type SelectorDefinitions<LogicType extends Logic> = | ||
connect?: any | ||
constants?: () => string[] | string[] | ||
constants?: (logic: LogicType) => string[] | string[] | ||
actions?: ActionDefinitions<LogicType> | ((logic: LogicType) => ActionDefinitions<LogicType>) | ||
@@ -179,17 +178,8 @@ reducers?: ReducerDefinitions<LogicType> | ((logic: LogicType) => ReducerDefinitions<LogicType>) | ||
events?: | ||
| { | ||
beforeMount?: (() => void) | (() => void)[] | ||
afterMount?: (() => void) | (() => void)[] | ||
beforeUnmount?: (() => void) | (() => void)[] | ||
afterUnmount?: (() => void) | (() => void)[] | ||
} | ||
| (( | ||
logic: LogicType, | ||
) => { | ||
beforeMount?: (() => void) | (() => void)[] | ||
afterMount?: (() => void) | (() => void)[] | ||
beforeUnmount?: (() => void) | (() => void)[] | ||
afterUnmount?: (() => void) | (() => void)[] | ||
}) | ||
defaults?: any | ||
| PartialRecord<LogicEventType, (() => void) | (() => void)[]> | ||
| ((logic: LogicType) => PartialRecord<LogicEventType, (() => void) | (() => void)[]>) | ||
defaults?: | ||
| ((logic: LogicType) => (state: any, props: LogicType['props']) => Record<string, any>) | ||
| ((logic: LogicType) => Record<string, any>) | ||
| Record<string, any> | ||
@@ -355,3 +345,3 @@ // plugins | ||
run: { | ||
heap: { action?: ReduxAction; type: 'action' | 'listener'; logic: BuiltLogic }[] | ||
heap: { action?: ReduxAction; type: 'action' | 'listener'; logic: Logic }[] | ||
} | ||
@@ -367,5 +357,5 @@ | ||
store?: Store | ||
store: Store | ||
options: InternalContextOptions | ||
} |
259446
6667
16