Comparing version 2.3.8 to 2.4.0
# Change Log | ||
All notable changes to this project will be documented in this file. | ||
## 2.4.0 - xxx | ||
- **Possibly Breaking:** Changed the [default path](https://kea.js.org/docs/guide/debugging#logic-path) for logic | ||
without a `path` (or when not using the kea babel plugin) from `kea.inline` to `kea.logic`. If you have ever hardcoded | ||
`"kea.inline"` anywhere, perhaps in tests, this will cause a bit of headache. If you need it set at `kea.inline`, use | ||
`resetContext({ defaultPath: ['kea', 'inline'] })`. | ||
- Added `<Provider />` tag to simplify calling React-Redux's `<Provider store={getContext().store} />`. | ||
- Fixed crashes with [React Fast Refresh](https://github.com/keajs/kea/issues/119). | ||
## 2.3.8 - 2021-04-26 | ||
@@ -5,0 +13,0 @@ - Fix regression introduced in 2.3.5 with default keys like: `key: props => props.id || 'default'` |
@@ -5,5 +5,8 @@ 'use strict'; | ||
function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'default' in ex) ? ex['default'] : ex; } | ||
var reselect = require('reselect'); | ||
var redux = require('redux'); | ||
var React = require('react'); | ||
var React__default = _interopDefault(React); | ||
var reactRedux = require('react-redux'); | ||
@@ -1379,4 +1382,4 @@ | ||
input: { | ||
inlinePathCreators: new Map(), | ||
inlinePathCounter: 0, | ||
logicPathCreators: new Map(), | ||
logicPathCounter: 0, | ||
defaults: defaults || undefined | ||
@@ -1414,3 +1417,4 @@ }, | ||
attachStrategy: 'dispatch', | ||
detachStrategy: 'dispatch' | ||
detachStrategy: 'dispatch', | ||
defaultPath: ['kea', 'logic'] | ||
}, otherOptions) | ||
@@ -1599,5 +1603,6 @@ }; | ||
var _getContext = getContext(), | ||
inlinePathCreators = _getContext.input.inlinePathCreators; | ||
logicPathCreators = _getContext.input.logicPathCreators, | ||
defaultPath = _getContext.options.defaultPath; | ||
var pathCreator = inlinePathCreators.get(input); | ||
var pathCreator = logicPathCreators.get(input); | ||
@@ -1608,15 +1613,15 @@ if (pathCreator) { | ||
var count = (++getContext().input.inlinePathCounter).toString(); | ||
var count = (++getContext().input.logicPathCounter).toString(); | ||
if (input.key) { | ||
pathCreator = function pathCreator(key) { | ||
return ['kea', 'inline', count, key]; | ||
return [].concat(defaultPath, [count, key]); | ||
}; | ||
} else { | ||
pathCreator = function pathCreator() { | ||
return ['kea', 'inline', count]; | ||
return [].concat(defaultPath, [count]); | ||
}; | ||
} | ||
inlinePathCreators.set(input, pathCreator); | ||
logicPathCreators.set(input, pathCreator); | ||
return pathCreator(key); | ||
@@ -2106,5 +2111,11 @@ } | ||
React.useEffect(function () { | ||
return function () { | ||
React.useEffect(function useMountedLogicEffect() { | ||
if (!unmount.current) { | ||
unmount.current = builtLogic.mount(); | ||
pathString.current = builtLogic.pathString; | ||
} | ||
return function useMountedLogicEffectCleanup() { | ||
unmount.current && unmount.current(); | ||
unmount.current = undefined; | ||
}; | ||
@@ -2137,2 +2148,9 @@ }, []); | ||
function Provider(_ref) { | ||
var children = _ref.children; | ||
return React__default.createElement(reactRedux.Provider, { | ||
store: getContext().store | ||
}, children); | ||
} | ||
var ATTACH_REDUCER$1 = ATTACH_REDUCER; | ||
@@ -2145,2 +2163,3 @@ var DETACH_REDUCER$1 = DETACH_REDUCER; | ||
exports.DETACH_REDUCER = DETACH_REDUCER$1; | ||
exports.Provider = Provider; | ||
exports.activatePlugin = activatePlugin; | ||
@@ -2147,0 +2166,0 @@ exports.addConnection = addConnection; |
import { AnyAction, Reducer, Middleware, compose, StoreEnhancer, Store, Action } from 'redux'; | ||
import { ComponentType, FunctionComponent, Context as Context$1, ReactNode } from 'react'; | ||
import React, { ComponentType, FunctionComponent, Context as Context$1, ReactNode } from 'react'; | ||
@@ -162,2 +162,3 @@ declare type AnyComponent = ComponentType | FunctionComponent; | ||
detachStrategy: 'dispatch' | 'replace' | 'persist'; | ||
defaultPath: string[]; | ||
} | ||
@@ -221,4 +222,4 @@ interface ContextOptions extends Partial<InternalContextOptions> { | ||
input: { | ||
inlinePathCreators: Map<LogicInput, PathCreator<any>>; | ||
inlinePathCounter: number; | ||
logicPathCreators: Map<LogicInput, PathCreator<any>>; | ||
logicPathCounter: number; | ||
defaults: Record<string, any> | undefined; | ||
@@ -272,2 +273,6 @@ }; | ||
declare function Provider({ children }: { | ||
children: React.ReactNode; | ||
}): JSX.Element; | ||
declare function getContext(): Context; | ||
@@ -304,2 +309,2 @@ declare function openContext(options?: ContextOptions, initial?: boolean): Context; | ||
export { ATTACH_REDUCER, AnyComponent, BindLogic, BreakPointFunction, BuiltLogic, BuiltLogicAdditions, Context, ContextOptions, CreateStoreOptions, DETACH_REDUCER, InternalContextOptions, KeaComponent, KeaPlugin, ListenerFunction, ListenerFunctionWrapper, Logic, LogicEventType, LogicInput, LogicWrapper, LogicWrapperAdditions, MakeLogicType, PartialRecord, PathCreator, PathType, PluginEventArrays, PluginEvents, Props, ReducerFunction, 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, BindLogic, BreakPointFunction, BuiltLogic, BuiltLogicAdditions, Context, ContextOptions, CreateStoreOptions, DETACH_REDUCER, InternalContextOptions, KeaComponent, KeaPlugin, ListenerFunction, ListenerFunctionWrapper, Logic, LogicEventType, LogicInput, LogicWrapper, LogicWrapperAdditions, MakeLogicType, PartialRecord, PathCreator, PathType, PluginEventArrays, PluginEvents, Props, Provider, ReducerFunction, RequiredPathCreator, Selector, activatePlugin, addConnection, closeContext, connect, createAction, getContext, getPluginContext, getStore, isBreakpoint, kea, keaReducer, openContext, resetContext, setPluginContext, useActions, useAllValues, useKea, useMountedLogic, useValues }; |
import { createSelector } from 'reselect'; | ||
import { applyMiddleware, compose, createStore } from 'redux'; | ||
import { useRef, useEffect, createElement, useMemo, createContext, useContext } from 'react'; | ||
import { connect as connect$1, useSelector } from 'react-redux'; | ||
import React__default, { useRef, useEffect, createElement, useMemo, createContext, useContext } from 'react'; | ||
import { connect as connect$1, useSelector, Provider as Provider$1 } from 'react-redux'; | ||
@@ -1374,4 +1374,4 @@ function _extends() { | ||
input: { | ||
inlinePathCreators: new Map(), | ||
inlinePathCounter: 0, | ||
logicPathCreators: new Map(), | ||
logicPathCounter: 0, | ||
defaults: defaults || undefined | ||
@@ -1409,3 +1409,4 @@ }, | ||
attachStrategy: 'dispatch', | ||
detachStrategy: 'dispatch' | ||
detachStrategy: 'dispatch', | ||
defaultPath: ['kea', 'logic'] | ||
}, otherOptions) | ||
@@ -1594,5 +1595,6 @@ }; | ||
var _getContext = getContext(), | ||
inlinePathCreators = _getContext.input.inlinePathCreators; | ||
logicPathCreators = _getContext.input.logicPathCreators, | ||
defaultPath = _getContext.options.defaultPath; | ||
var pathCreator = inlinePathCreators.get(input); | ||
var pathCreator = logicPathCreators.get(input); | ||
@@ -1603,15 +1605,15 @@ if (pathCreator) { | ||
var count = (++getContext().input.inlinePathCounter).toString(); | ||
var count = (++getContext().input.logicPathCounter).toString(); | ||
if (input.key) { | ||
pathCreator = function pathCreator(key) { | ||
return ['kea', 'inline', count, key]; | ||
return [].concat(defaultPath, [count, key]); | ||
}; | ||
} else { | ||
pathCreator = function pathCreator() { | ||
return ['kea', 'inline', count]; | ||
return [].concat(defaultPath, [count]); | ||
}; | ||
} | ||
inlinePathCreators.set(input, pathCreator); | ||
logicPathCreators.set(input, pathCreator); | ||
return pathCreator(key); | ||
@@ -2101,5 +2103,11 @@ } | ||
useEffect(function () { | ||
return function () { | ||
useEffect(function useMountedLogicEffect() { | ||
if (!unmount.current) { | ||
unmount.current = builtLogic.mount(); | ||
pathString.current = builtLogic.pathString; | ||
} | ||
return function useMountedLogicEffectCleanup() { | ||
unmount.current && unmount.current(); | ||
unmount.current = undefined; | ||
}; | ||
@@ -2132,2 +2140,9 @@ }, []); | ||
function Provider(_ref) { | ||
var children = _ref.children; | ||
return React__default.createElement(Provider$1, { | ||
store: getContext().store | ||
}, children); | ||
} | ||
var ATTACH_REDUCER$1 = ATTACH_REDUCER; | ||
@@ -2137,2 +2152,2 @@ var DETACH_REDUCER$1 = DETACH_REDUCER; | ||
export { ATTACH_REDUCER$1 as ATTACH_REDUCER, BindLogic, DETACH_REDUCER$1 as DETACH_REDUCER, activatePlugin, addConnection, closeContext, connect, createAction, getContext, getPluginContext, getStore, isBreakpoint, kea, keaReducer, openContext, resetContext, setPluginContext, useActions, useAllValues, useKea, useMountedLogic, useValues }; | ||
export { ATTACH_REDUCER$1 as ATTACH_REDUCER, BindLogic, DETACH_REDUCER$1 as DETACH_REDUCER, Provider, activatePlugin, addConnection, closeContext, connect, createAction, getContext, getPluginContext, getStore, isBreakpoint, kea, keaReducer, openContext, resetContext, setPluginContext, useActions, useAllValues, useKea, useMountedLogic, useValues }; |
@@ -5,2 +5,3 @@ export * from './types'; | ||
export { BindLogic } from './react/bind'; | ||
export { Provider } from './react/provider'; | ||
export { resetContext, openContext, closeContext, getContext, getPluginContext, setPluginContext } from './context'; | ||
@@ -7,0 +8,0 @@ export { getStore } from './store/store'; |
@@ -161,2 +161,3 @@ import { Reducer, Store, Action as ReduxAction, Middleware, StoreEnhancer, compose, AnyAction } from 'redux'; | ||
detachStrategy: 'dispatch' | 'replace' | 'persist'; | ||
defaultPath: string[]; | ||
} | ||
@@ -220,4 +221,4 @@ export interface ContextOptions extends Partial<InternalContextOptions> { | ||
input: { | ||
inlinePathCreators: Map<LogicInput, PathCreator<any>>; | ||
inlinePathCounter: number; | ||
logicPathCreators: Map<LogicInput, PathCreator<any>>; | ||
logicPathCounter: number; | ||
defaults: Record<string, any> | undefined; | ||
@@ -224,0 +225,0 @@ }; |
{ | ||
"name": "kea", | ||
"version": "2.3.8", | ||
"version": "2.4.0", | ||
"description": "Smart front-end architecture", | ||
@@ -5,0 +5,0 @@ "author": "Marius Andra", |
@@ -38,4 +38,4 @@ import { corePlugin } from '../core' | ||
input: { | ||
inlinePathCreators: new Map(), | ||
inlinePathCounter: 0, | ||
logicPathCreators: new Map(), | ||
logicPathCounter: 0, | ||
defaults: defaults || undefined, | ||
@@ -81,3 +81,3 @@ }, | ||
detachStrategy: 'dispatch', | ||
defaultPath: ['kea', 'logic'], | ||
...otherOptions, | ||
@@ -84,0 +84,0 @@ }, |
@@ -6,4 +6,6 @@ export * from './types' | ||
export { kea, connect } from './kea' | ||
export { useValues, useAllValues, useActions, useMountedLogic, useKea } from './react/hooks' | ||
export { BindLogic } from './react/bind' | ||
export { Provider } from './react/provider' | ||
@@ -10,0 +12,0 @@ export { resetContext, openContext, closeContext, getContext, getPluginContext, setPluginContext } from './context' |
@@ -12,6 +12,7 @@ import { getContext } from '../context' | ||
const { | ||
input: { inlinePathCreators }, | ||
input: { logicPathCreators }, | ||
options: { defaultPath }, | ||
} = getContext() | ||
let pathCreator = inlinePathCreators.get(input) | ||
let pathCreator = logicPathCreators.get(input) | ||
@@ -22,11 +23,11 @@ if (pathCreator) { | ||
const count = (++getContext().input.inlinePathCounter).toString() | ||
const count = (++getContext().input.logicPathCounter).toString() | ||
if (input.key) { | ||
pathCreator = ((key: string) => ['kea', 'inline', count, key]) as PathCreator | ||
pathCreator = (key: string) => [...defaultPath, count, key] | ||
} else { | ||
pathCreator = () => ['kea', 'inline', count] | ||
pathCreator = () => [...defaultPath, count] | ||
} | ||
inlinePathCreators.set(input, pathCreator) | ||
logicPathCreators.set(input, pathCreator) | ||
@@ -33,0 +34,0 @@ return pathCreator(key) |
@@ -72,10 +72,18 @@ import { useMemo, useEffect, useRef, useContext, createContext } from 'react' | ||
useEffect( | ||
() => () => { | ||
useEffect(function useMountedLogicEffect () { | ||
// React Fast Refresh calls `useMountedLogicEffectCleanup` followed directly by `useMountedLogicEffect`. | ||
// Thus if we're here and there's still no `unmount.current`, it's because we just refreshed. | ||
// Normally we still mount the logic sync in the component, just to have the data there when selectors fire. | ||
if (!unmount.current) { | ||
unmount.current = builtLogic.mount() | ||
pathString.current = builtLogic.pathString | ||
} | ||
return function useMountedLogicEffectCleanup() { | ||
unmount.current && unmount.current() | ||
}, | ||
[], | ||
) | ||
unmount.current = undefined | ||
} | ||
}, []) | ||
return builtLogic | ||
} |
@@ -281,2 +281,3 @@ import { Reducer, Store, Action as ReduxAction, Middleware, StoreEnhancer, compose, AnyAction } from 'redux' | ||
detachStrategy: 'dispatch' | 'replace' | 'persist' | ||
defaultPath: string[] | ||
// ...otherOptions | ||
@@ -346,4 +347,4 @@ } | ||
input: { | ||
inlinePathCreators: Map<LogicInput, PathCreator<any>> | ||
inlinePathCounter: number | ||
logicPathCreators: Map<LogicInput, PathCreator<any>> | ||
logicPathCounter: number | ||
defaults: Record<string, any> | undefined | ||
@@ -350,0 +351,0 @@ } |
284751
75
7092