File tree Expand file tree Collapse file tree 5 files changed +26
-8
lines changed
Expand file tree Collapse file tree 5 files changed +26
-8
lines changed Original file line number Diff line number Diff line change 1+ ---
2+ " mobx-view-model " : minor
3+ ---
4+
5+ added ` ActiveViewModelProvider ` internal HOC
Original file line number Diff line number Diff line change 1+ import type { ReactNode } from 'react' ;
2+ import { ActiveViewModelContext } from '../contexts/index.js' ;
3+ import type { AnyViewModel , AnyViewModelSimple } from '../view-model/index.js' ;
4+
5+ /**
6+ * This is a provider for the `ActiveViewModelContext`.
7+ * This HOC is not recommended for public usage.
8+ * Better to use `withViewModel` HOC.
9+ */
10+ export const ActiveViewModelProvider =
11+ ActiveViewModelContext . Provider as unknown as React . ComponentType < {
12+ value : AnyViewModel | AnyViewModelSimple ;
13+ children ?: ReactNode ;
14+ } > ;
Original file line number Diff line number Diff line change 1+ export * from './active-view-model-provider.js' ;
12export * from './only-view-model.js' ;
23export * from './view-models-provider.js' ;
Original file line number Diff line number Diff line change @@ -11,11 +11,9 @@ import type {
1111 IsUnknown ,
1212 Maybe ,
1313} from 'yummies/types' ;
14+ import { ActiveViewModelProvider } from '../components/active-view-model-provider.js' ;
1415import { viewModelsConfig } from '../config/index.js' ;
15- import {
16- ActiveViewModelContext ,
17- ViewModelsContext ,
18- } from '../contexts/index.js' ;
16+ import { ViewModelsContext } from '../contexts/index.js' ;
1917import {
2018 type UseCreateViewModelConfig ,
2119 useCreateViewModel ,
@@ -385,9 +383,9 @@ const withViewModelWrapper = (
385383
386384 if ( isRenderAllowed ) {
387385 return (
388- < ActiveViewModelContext . Provider value = { model } >
386+ < ActiveViewModelProvider value = { model } >
389387 { Component && < Component { ...componentProps } model = { model } /> }
390- </ ActiveViewModelContext . Provider >
388+ </ ActiveViewModelProvider >
391389 ) ;
392390 }
393391
Original file line number Diff line number Diff line change @@ -108,7 +108,7 @@ const useCreateViewModelBase = (
108108 config ?: Maybe < UseCreateViewModelConfig < AnyViewModel > > ,
109109) => {
110110 const viewModels = useContext ( ViewModelsContext ) ;
111- const parentViewModel = useContext ( ActiveViewModelContext ) || null ;
111+ const parentViewModel = useContext ( ActiveViewModelContext ) ;
112112
113113 const ctx = config ?. ctx ?? { } ;
114114
@@ -180,7 +180,7 @@ const useCreateViewModelSimple = (
180180 payload ?: any ,
181181) => {
182182 const viewModels = useContext ( ViewModelsContext ) ;
183- const parentViewModel = useContext ( ActiveViewModelContext ) || null ;
183+ const parentViewModel = useContext ( ActiveViewModelContext ) ;
184184
185185 const instance = useValue ( ( ) => {
186186 const instance = new VM ( ) ;
You can’t perform that action at this time.
0 commit comments