@@ -49,16 +49,16 @@ export default class Container extends Component {
4949 // These fallbacks are needed only to make enzyme shallow work
5050 // as it does not fully support provider-less Context enzyme#1553
5151 globalRegistry = defaultRegistry ,
52- getStore = defaultRegistry . getStore ,
52+ retrieveStore = defaultRegistry . getStore ,
5353 } = this . context ;
5454
5555 this . state = {
5656 api : {
5757 globalRegistry,
58- getStore : ( Store , scope ) =>
58+ retrieveStore : ( Store , scope ) =>
5959 this . constructor . storeType === Store
6060 ? this . getScopedStore ( scope )
61- : getStore ( Store ) ,
61+ : retrieveStore ( Store ) ,
6262 } ,
6363 // stored to make them available in getDerivedStateFromProps
6464 // as js context there is null https://github.com/facebook/react/issues/12612
@@ -103,20 +103,15 @@ export default class Container extends Component {
103103 const { storeType, hooks } = this . constructor ;
104104 const { api } = this . state ;
105105 // we explicitly pass scope as it might be changed
106- const { storeState } = api . getStore ( storeType , scope ) ;
106+ const { storeState } = api . retrieveStore ( storeType , scope ) ;
107107
108- const actions = bindActions (
109- storeType . actions ,
110- storeState ,
111- this . getContainerProps
112- ) ;
108+ const config = {
109+ props : ( ) => this . actionProps ,
110+ contained : ( s ) => storeType === s ,
111+ } ;
113112
114- this . scopedHooks = bindActions (
115- hooks ,
116- storeState ,
117- this . getContainerProps ,
118- actions
119- ) ;
113+ const actions = bindActions ( storeType . actions , storeState , config ) ;
114+ this . scopedHooks = bindActions ( hooks , storeState , config , actions ) ;
120115
121116 // make sure we also reset actionProps
122117 this . actionProps = null ;
@@ -146,8 +141,6 @@ export default class Container extends Component {
146141 return restProps ;
147142 } ;
148143
149- getContainerProps = ( ) => this . actionProps ;
150-
151144 getRegistry ( ) {
152145 const isLocal = ! this . props . scope && ! this . props . isGlobal ;
153146 return isLocal ? this . registry : this . state . api . globalRegistry ;
@@ -224,15 +217,15 @@ function useRegistry(scope, isGlobal, { globalRegistry }) {
224217 } , [ scope , isGlobal , globalRegistry ] ) ;
225218}
226219
227- function useContainedStore ( scope , registry , props , override ) {
220+ function useContainedStore ( scope , registry , props , check , override ) {
228221 // Store contained scopes in a map, but throwing it away on scope change
229222 // eslint-disable-next-line react-hooks/exhaustive-deps
230223 const containedStores = useMemo ( ( ) => new Map ( ) , [ scope ] ) ;
231224
232225 // Store props in a ref to avoid re-binding actions when they change and re-rendering all
233226 // consumers unnecessarily. The update is handled by an effect on the component instead
234- const containerProps = useRef ( ) ;
235- containerProps . current = props ;
227+ const propsRef = useRef ( ) ;
228+ propsRef . current = props ;
236229
237230 const getContainedStore = useCallback (
238231 ( Store ) => {
@@ -241,13 +234,12 @@ function useContainedStore(scope, registry, props, override) {
241234 // so we can provide props to actions (only triggered by children)
242235 if ( ! containedStore ) {
243236 const isExisting = registry . hasStore ( Store , scope ) ;
244- const { storeState } = registry . getStore ( Store , scope , true ) ;
245- const getProps = ( ) => containerProps . current ;
246- const actions = bindActions ( Store . actions , storeState , getProps ) ;
237+ const config = { props : ( ) => propsRef . current , contained : check } ;
238+ const { storeState, actions } = registry . getStore ( Store , scope , config ) ;
247239 const handlers = bindActions (
248240 { ...Store . handlers , ...override ?. handlers } ,
249241 storeState ,
250- getProps ,
242+ config ,
251243 actions
252244 ) ;
253245 containedStore = {
@@ -263,20 +255,20 @@ function useContainedStore(scope, registry, props, override) {
263255 }
264256 return containedStore ;
265257 } ,
266- [ containedStores , registry , scope , override ]
258+ [ containedStores , registry , scope , check , override ]
267259 ) ;
268260 return [ containedStores , getContainedStore ] ;
269261}
270262
271- function useApi ( check , getContainedStore , { globalRegistry, getStore } ) {
272- const getStoreRef = useRef ( ) ;
273- getStoreRef . current = ( Store ) =>
274- check ( Store ) ? getContainedStore ( Store ) : getStore ( Store ) ;
263+ function useApi ( check , getContainedStore , { globalRegistry, retrieveStore } ) {
264+ const retrieveRef = useRef ( ) ;
265+ retrieveRef . current = ( Store ) =>
266+ check ( Store ) ? getContainedStore ( Store ) : retrieveStore ( Store ) ;
275267
276268 // This api is "frozen", as changing it will trigger re-render across all consumers
277- // so we link getStore dynamically and manually call notify() on scope change
269+ // so we link retrieveStore dynamically and manually call notify() on scope change
278270 return useMemo (
279- ( ) => ( { globalRegistry, getStore : ( s ) => getStoreRef . current ( s ) } ) ,
271+ ( ) => ( { globalRegistry, retrieveStore : ( s ) => retrieveRef . current ( s ) } ) ,
280272 [ globalRegistry ]
281273 ) ;
282274}
@@ -294,6 +286,7 @@ function createFunctionContainer({ displayName, override } = {}) {
294286 scope ,
295287 registry ,
296288 restProps ,
289+ check ,
297290 override
298291 ) ;
299292 const api = useApi ( check , getContainedStore , ctx ) ;
@@ -329,7 +322,7 @@ function createFunctionContainer({ displayName, override } = {}) {
329322 ! storeState . listeners ( ) . size &&
330323 // ensure registry has not already created a new store with same scope
331324 storeState ===
332- registry . getStore ( Store , cachedScope , true ) . storeState
325+ registry . getStore ( Store , cachedScope , null ) ? .storeState
333326 ) {
334327 handlers . onDestroy ?. ( ) ;
335328 registry . deleteStore ( Store , cachedScope ) ;
0 commit comments