Comparing version 3.0.0-alpha.1 to 3.0.0-alpha.2
@@ -436,3 +436,3 @@ 'use strict'; | ||
function getStore(opts) { | ||
function createStore(opts) { | ||
if (opts === void 0) { | ||
@@ -509,3 +509,3 @@ opts = {}; | ||
_options$createStore = _options.createStore, | ||
createStore = _options$createStore === void 0 ? true : _options$createStore, | ||
createStoreOptions = _options$createStore === void 0 ? true : _options$createStore, | ||
defaults = _options.defaults, | ||
@@ -555,4 +555,4 @@ otherOptions = _objectWithoutPropertiesLoose(_options, _excluded); | ||
if (!store && createStore) { | ||
return getStore(typeof createStore === 'object' ? createStore : {}); | ||
if (!store && createStoreOptions) { | ||
return createStore(typeof createStoreOptions === 'object' ? createStoreOptions : {}); | ||
} | ||
@@ -577,3 +577,3 @@ | ||
if (!initial && createStore) { | ||
if (!initial && createStoreOptions) { | ||
context.store; | ||
@@ -2003,2 +2003,3 @@ } | ||
exports.createActionCreator = createActionCreator; | ||
exports.createStore = createStore; | ||
exports.defaults = defaults; | ||
@@ -2008,3 +2009,2 @@ exports.events = events; | ||
exports.getPluginContext = getPluginContext; | ||
exports.getStore = getStore; | ||
exports.isBreakpoint = isBreakpoint; | ||
@@ -2011,0 +2011,0 @@ exports.isBuiltLogic = isBuiltLogic; |
@@ -345,3 +345,3 @@ import { AnyAction, Reducer, Middleware, compose, StoreEnhancer, Store } from 'redux'; | ||
declare function getStore(opts?: {}): Store | void; | ||
declare function createStore(opts?: {}): Store | void; | ||
@@ -355,2 +355,2 @@ declare function keaReducer(pathStart?: string): ReducerFunction; | ||
export { ATTACH_REDUCER, ActionCreatorForPayloadBuilder, ActionDefinitions, ActionForPayloadBuilder, AnyComponent, BindLogic, BreakPointFunction, BuiltLogic, BuiltLogicAdditions, Context, ContextOptions, CreateStoreOptions, DETACH_REDUCER, InternalContextOptions, KeaAction, KeaComponent, KeaPlugin, KeaReduxAction, KeyType, ListenerFunction, ListenerFunctionWrapper, Logic, LogicBuilder, LogicEventType, LogicInput, LogicWrapper, LogicWrapperAdditions, MakeLogicType, PartialRecord, PathType, PluginEventArrays, PluginEvents, Props, Provider, ReducerDefinitions, ReducerFunction, Selector, SelectorDefinition, SelectorDefinitions, SelectorTuple, WrapperContext, actions, activatePlugin, addConnection, afterMount, beforeUnmount, closeContext, connect, corePlugin, createActionCreator, defaults, events, getContext, getPluginContext, getStore, isBreakpoint, isBuiltLogic, isLogicWrapper, kea, keaReducer, key, listeners, openContext, path, props, reducers, resetContext, selectors, setPluginContext, sharedListeners, useActions, useAllValues, useKea, useMountedLogic, useValues }; | ||
export { ATTACH_REDUCER, ActionCreatorForPayloadBuilder, ActionDefinitions, ActionForPayloadBuilder, AnyComponent, AnyFunction, BindLogic, BreakPointFunction, BuiltLogic, BuiltLogicAdditions, Context, ContextOptions, CreateStoreOptions, DETACH_REDUCER, InternalContextOptions, KeaAction, KeaComponent, KeaPlugin, KeaReduxAction, KeyType, ListenerDefinitions, ListenerDefinitionsForRecord, ListenerFunction, ListenerFunctionWrapper, Logic, LogicBuilder, LogicEventType, LogicInput, LogicWrapper, LogicWrapperAdditions, MakeLogicType, PartialRecord, PathType, PluginEventArrays, PluginEvents, Props, Provider, ReducerActions, ReducerDefault, ReducerDefinitions, ReducerFunction, Selector, SelectorDefinition, SelectorDefinitions, SelectorTuple, SharedListenerDefinitions, WrapperContext, actions, activatePlugin, addConnection, afterMount, beforeUnmount, closeContext, connect, corePlugin, createActionCreator, createStore, defaults, events, getContext, getPluginContext, isBreakpoint, isBuiltLogic, isLogicWrapper, kea, keaReducer, key, listeners, openContext, path, props, reducers, resetContext, selectors, setPluginContext, sharedListeners, useActions, useAllValues, useKea, useMountedLogic, useValues }; |
@@ -1,2 +0,2 @@ | ||
import { applyMiddleware, compose, createStore } from 'redux'; | ||
import { applyMiddleware, compose, createStore as createStore$1 } from 'redux'; | ||
import { createSelector } from 'reselect'; | ||
@@ -408,3 +408,3 @@ import * as React from 'react'; | ||
function getStore(opts) { | ||
function createStore(opts) { | ||
if (opts === void 0) { | ||
@@ -435,3 +435,3 @@ opts = {}; | ||
var composeEnchancer = options.compose || compose; | ||
var finalCreateStore = composeEnchancer.apply(void 0, options.enhancers)(createStore); | ||
var finalCreateStore = composeEnchancer.apply(void 0, options.enhancers)(createStore$1); | ||
@@ -482,3 +482,3 @@ if (options.paths && options.paths.length > 0) { | ||
_options$createStore = _options.createStore, | ||
createStore = _options$createStore === void 0 ? true : _options$createStore, | ||
createStoreOptions = _options$createStore === void 0 ? true : _options$createStore, | ||
defaults = _options.defaults, | ||
@@ -528,4 +528,4 @@ otherOptions = _objectWithoutPropertiesLoose(_options, _excluded); | ||
if (!store && createStore) { | ||
return getStore(typeof createStore === 'object' ? createStore : {}); | ||
if (!store && createStoreOptions) { | ||
return createStore(typeof createStoreOptions === 'object' ? createStoreOptions : {}); | ||
} | ||
@@ -550,3 +550,3 @@ | ||
if (!initial && createStore) { | ||
if (!initial && createStoreOptions) { | ||
context.store; | ||
@@ -1963,2 +1963,2 @@ } | ||
export { ATTACH_REDUCER, BindLogic, DETACH_REDUCER, Provider, actions, activatePlugin, addConnection, afterMount, beforeUnmount, closeContext, connect, corePlugin, createActionCreator, defaults, events, getContext, getPluginContext, getStore, isBreakpoint, isBuiltLogic, isLogicWrapper, kea, keaReducer, key, listeners, openContext, path, props, reducers, resetContext, selectors, setPluginContext, sharedListeners, useActions, useAllValues, useKea, useMountedLogic, useValues }; | ||
export { ATTACH_REDUCER, BindLogic, DETACH_REDUCER, Provider, actions, activatePlugin, addConnection, afterMount, beforeUnmount, closeContext, connect, corePlugin, createActionCreator, createStore, defaults, events, getContext, getPluginContext, isBreakpoint, isBuiltLogic, isLogicWrapper, kea, keaReducer, key, listeners, openContext, path, props, reducers, resetContext, selectors, setPluginContext, sharedListeners, useActions, useAllValues, useKea, useMountedLogic, useValues }; |
@@ -9,3 +9,3 @@ export * from './types'; | ||
export { resetContext, openContext, closeContext, getContext, getPluginContext, setPluginContext } from './kea/context'; | ||
export { getStore } from './kea/store'; | ||
export { createStore } from './kea/store'; | ||
export { keaReducer } from './kea/reducer'; | ||
@@ -12,0 +12,0 @@ export { activatePlugin } from './kea/plugins'; |
import { Store } from 'redux'; | ||
export declare function getStore(opts?: {}): Store | void; | ||
export declare function createStore(opts?: {}): Store | void; |
@@ -71,3 +71,3 @@ import { Reducer, Store, Middleware, StoreEnhancer, compose, AnyAction } from 'redux'; | ||
} | ||
declare type ReducerActions<LogicType extends Logic, ReducerType> = { | ||
export declare type ReducerActions<LogicType extends Logic, ReducerType> = { | ||
[K in keyof LogicType['actionCreators']]?: (state: ReducerType, payload: ReturnType<LogicType['actionCreators'][K]>['payload']) => ReducerType; | ||
@@ -77,3 +77,3 @@ } & { | ||
}; | ||
declare type ReducerDefault<Reducer extends () => any, P extends Props> = ReturnType<Reducer> | ((state: any, props: P) => ReturnType<Reducer>); | ||
export declare type ReducerDefault<Reducer extends () => any, P extends Props> = ReturnType<Reducer> | ((state: any, props: P) => ReturnType<Reducer>); | ||
export declare type ReducerDefinitions<LogicType extends Logic> = { | ||
@@ -94,9 +94,9 @@ [K in keyof LogicType['reducers']]?: [ | ||
export declare type BreakPointFunction = (() => void) & ((ms: number) => Promise<void>); | ||
declare type ListenerDefinitionsForRecord<A extends Record<string, (...args: any) => any>> = { | ||
export declare type ListenerDefinitionsForRecord<A extends Record<string, (...args: any) => any>> = { | ||
[K in keyof A]?: ListenerFunction<ReturnType<A[K]>> | ListenerFunction<ReturnType<A[K]>>[]; | ||
}; | ||
declare type ListenerDefinitions<LogicType extends Logic> = ListenerDefinitionsForRecord<LogicType['actionCreators']> & ListenerDefinitionsForRecord<LogicType['__keaTypeGenInternalReducerActions']>; | ||
export declare type ListenerDefinitions<LogicType extends Logic> = ListenerDefinitionsForRecord<LogicType['actionCreators']> & ListenerDefinitionsForRecord<LogicType['__keaTypeGenInternalReducerActions']>; | ||
export declare type ListenerFunction<A extends AnyAction = any> = (payload: A['payload'], breakpoint: BreakPointFunction, action: A, previousState: any) => void | Promise<void>; | ||
export declare type ListenerFunctionWrapper = (action: any, previousState: any) => void; | ||
declare type SharedListenerDefinitions = Record<string, ListenerFunction>; | ||
export declare type SharedListenerDefinitions = Record<string, ListenerFunction>; | ||
declare type WindowValuesDefinitions<LogicType extends Logic> = Record<string, (window: Window) => any>; | ||
@@ -183,3 +183,3 @@ declare type LoaderFunctions<LogicType extends Logic, ReducerReturnType> = { | ||
} | ||
declare type AnyFunction = (...args: any) => any; | ||
export declare type AnyFunction = (...args: any) => any; | ||
export declare type ActionCreatorForPayloadBuilder<B extends AnyFunction> = (...args: Parameters<B>) => { | ||
@@ -186,0 +186,0 @@ type: string; |
{ | ||
"name": "kea", | ||
"version": "3.0.0-alpha.1", | ||
"version": "3.0.0-alpha.2", | ||
"description": "Smart front-end architecture", | ||
@@ -64,3 +64,2 @@ "author": "Marius Andra", | ||
"peerDependencies": { | ||
"kea": ">= 2", | ||
"react": ">= 16", | ||
@@ -67,0 +66,0 @@ "react-redux": ">= 7", |
@@ -14,3 +14,3 @@ export * from './types' | ||
export { resetContext, openContext, closeContext, getContext, getPluginContext, setPluginContext } from './kea/context' | ||
export { getStore } from './kea/store' | ||
export { createStore } from './kea/store' | ||
export { keaReducer } from './kea/reducer' | ||
@@ -17,0 +17,0 @@ export { activatePlugin } from './kea/plugins' |
import { activatePlugin, runPlugins } from './plugins' | ||
import { getStore } from './store' | ||
import { createStore } from './store' | ||
import { Context, ContextOptions } from '../types' | ||
@@ -26,3 +26,3 @@ import { Store } from 'redux' | ||
const { plugins, createStore = true, defaults, ...otherOptions } = options | ||
const { plugins, createStore: createStoreOptions = true, defaults, ...otherOptions } = options | ||
@@ -78,4 +78,4 @@ const newContext = { | ||
const store: Store = (newContext as any)['__store'] | ||
if (!store && createStore) { | ||
return getStore(typeof createStore === 'object' ? createStore : {}) | ||
if (!store && createStoreOptions) { | ||
return createStore(typeof createStoreOptions === 'object' ? createStoreOptions : {}) | ||
} | ||
@@ -101,3 +101,3 @@ return store | ||
if (!initial && createStore) { | ||
if (!initial && createStoreOptions) { | ||
context.store // trigger the getter that creates the store | ||
@@ -104,0 +104,0 @@ } |
@@ -1,2 +0,2 @@ | ||
import { createStore, applyMiddleware, compose, Store, StoreEnhancer } from 'redux' | ||
import { createStore as reduxCreateStore, applyMiddleware, compose, Store, StoreEnhancer } from 'redux' | ||
@@ -25,3 +25,3 @@ import { createReduxStoreReducer, initRootReducerTree } from './reducer' | ||
export function getStore(opts = {}): Store | void { | ||
export function createStore(opts = {}): Store | void { | ||
const context = getContext() | ||
@@ -57,3 +57,3 @@ | ||
// create the store creator | ||
const finalCreateStore = composeEnchancer(...options.enhancers)(createStore) as typeof createStore | ||
const finalCreateStore = composeEnchancer(...options.enhancers)(reduxCreateStore) as typeof reduxCreateStore | ||
@@ -60,0 +60,0 @@ // if we are whitelisting paths |
@@ -98,3 +98,3 @@ import { Reducer, Store, Middleware, StoreEnhancer, compose, AnyAction } from 'redux' | ||
type ReducerActions<LogicType extends Logic, ReducerType> = { | ||
export type ReducerActions<LogicType extends Logic, ReducerType> = { | ||
[K in keyof LogicType['actionCreators']]?: ( | ||
@@ -111,3 +111,3 @@ state: ReducerType, | ||
type ReducerDefault<Reducer extends () => any, P extends Props> = | ||
export type ReducerDefault<Reducer extends () => any, P extends Props> = | ||
| ReturnType<Reducer> | ||
@@ -159,7 +159,7 @@ | ((state: any, props: P) => ReturnType<Reducer>) | ||
type ListenerDefinitionsForRecord<A extends Record<string, (...args: any) => any>> = { | ||
export type ListenerDefinitionsForRecord<A extends Record<string, (...args: any) => any>> = { | ||
[K in keyof A]?: ListenerFunction<ReturnType<A[K]>> | ListenerFunction<ReturnType<A[K]>>[] | ||
} | ||
type ListenerDefinitions<LogicType extends Logic> = ListenerDefinitionsForRecord<LogicType['actionCreators']> & | ||
export type ListenerDefinitions<LogicType extends Logic> = ListenerDefinitionsForRecord<LogicType['actionCreators']> & | ||
ListenerDefinitionsForRecord<LogicType['__keaTypeGenInternalReducerActions']> | ||
@@ -176,3 +176,3 @@ | ||
type SharedListenerDefinitions = Record<string, ListenerFunction> | ||
export type SharedListenerDefinitions = Record<string, ListenerFunction> | ||
@@ -270,9 +270,12 @@ type WindowValuesDefinitions<LogicType extends Logic> = Record<string, (window: Window) => any> | ||
// MakeLogicType: | ||
// - create a close-enough approximation of the logic's types if passed two interfaces: | ||
// | ||
// MakeLogicType<Values, Actions> | ||
// - Values = { valueKey: type } | ||
// - Actions = { actionKey: (id) => void } // <- this works | ||
// - Actions = { actionKey: (id) => { id } } // <- adds type completion in reducers | ||
/** | ||
MakeLogicType: | ||
- create a close-enough approximation of the logic's types if passed three interfaces: | ||
MakeLogicType<Values, Actions, Props> | ||
- Values = { valueKey: type } | ||
- Actions = { actionKey: (id) => void } // <- this works | ||
- Actions = { actionKey: (id) => { id } } // <- adds type completion in reducers | ||
- Props = { id: 3 } | ||
*/ | ||
export interface MakeLogicType< | ||
@@ -313,3 +316,3 @@ Values = Record<string, unknown>, | ||
} | ||
type AnyFunction = (...args: any) => any | ||
export type AnyFunction = (...args: any) => any | ||
@@ -316,0 +319,0 @@ export type ActionCreatorForPayloadBuilder<B extends AnyFunction> = (...args: Parameters<B>) => { |
284955
4
6977