bloc-react
Advanced tools
Comparing version 0.0.14-3 to 0.0.14-4
import { Subscription } from 'rxjs'; | ||
import React, { ReactElement } from 'react'; | ||
import { ReactElement } from 'react'; | ||
@@ -122,13 +122,13 @@ declare type ValueType<T extends BlocBase<any>> = T extends BlocBase<infer U> ? U : never; | ||
useBloc: <T extends BlocBase<any>>(blocClass: BlocClass<T>, options?: BlocHookOptions<T>) => BlocHookData<T>; | ||
BlocBuilder: <T extends BlocBase<any>>(props: { | ||
BlocBuilder<T extends BlocBase<any>>(props: { | ||
blocClass: BlocClass<T>; | ||
builder: (data: BlocHookData<T>) => ReactElement; | ||
shouldUpdate?: ((previousState: ValueType<T>, state: ValueType<T>) => boolean) | undefined; | ||
}) => ReactElement | null; | ||
BlocProvider: <T extends BlocBase<any>>(props: { | ||
children?: React.ReactElement<any, string | React.JSXElementConstructor<any>> | React.ReactElement<any, string | React.JSXElementConstructor<any>>[] | undefined; | ||
shouldUpdate?: (previousState: ValueType<T>, state: ValueType<T>) => boolean; | ||
}): ReactElement | null; | ||
BlocProvider<T extends BlocBase<any>>(props: { | ||
children?: ReactElement | ReactElement[]; | ||
create: (providerKey: string) => T; | ||
}) => ReactElement; | ||
}): ReactElement; | ||
} | ||
export { Bloc, BlocReact, Cubit }; |
@@ -312,32 +312,32 @@ 'use strict'; | ||
}; | ||
this.BlocBuilder = (props) => { | ||
const hook = this.useBloc(props.blocClass, { | ||
shouldUpdate: props.shouldUpdate | ||
}); | ||
return props.builder(hook); | ||
}; | ||
this.BlocProvider = (props) => { | ||
const providerKey = React.useMemo(() => "p_" + nanoid.nanoid(), []); | ||
const bloc = React.useMemo(() => { | ||
const newBloc = props.create(providerKey); | ||
newBloc._localProviderRef = providerKey; | ||
this.addLocalBloc(providerKey, newBloc); | ||
return newBloc; | ||
}, []); | ||
const context = React.useMemo(() => { | ||
return React__default['default'].createContext(bloc); | ||
}, [bloc]); | ||
React.useEffect(() => { | ||
return () => { | ||
this.removeLocalBloc(providerKey); | ||
}; | ||
}, []); | ||
return /* @__PURE__ */ React__default['default'].createElement(this._contextLocalProviderKey.Provider, { | ||
value: providerKey | ||
}, /* @__PURE__ */ React__default['default'].createElement(context.Provider, { | ||
value: bloc | ||
}, props.children)); | ||
}; | ||
this._blocsGlobal = blocs; | ||
} | ||
BlocBuilder(props) { | ||
const hook = this.useBloc(props.blocClass, { | ||
shouldUpdate: props.shouldUpdate | ||
}); | ||
return props.builder(hook); | ||
} | ||
BlocProvider(props) { | ||
const providerKey = React.useMemo(() => "p_" + nanoid.nanoid(), []); | ||
const bloc = React.useMemo(() => { | ||
const newBloc = props.create(providerKey); | ||
newBloc._localProviderRef = providerKey; | ||
this.addLocalBloc(providerKey, newBloc); | ||
return newBloc; | ||
}, []); | ||
const context = React.useMemo(() => { | ||
return React__default['default'].createContext(bloc); | ||
}, [bloc]); | ||
React.useEffect(() => { | ||
return () => { | ||
this.removeLocalBloc(providerKey); | ||
}; | ||
}, []); | ||
return /* @__PURE__ */ React__default['default'].createElement(this._contextLocalProviderKey.Provider, { | ||
value: providerKey | ||
}, /* @__PURE__ */ React__default['default'].createElement(context.Provider, { | ||
value: bloc | ||
}, props.children)); | ||
} | ||
} | ||
@@ -344,0 +344,0 @@ |
{ | ||
"name": "bloc-react", | ||
"version": "0.0.14-3", | ||
"version": "0.0.14-4", | ||
"scripts": { | ||
@@ -5,0 +5,0 @@ "dev": "vite", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
72011