@brushes/context 0.0.6 → 0.0.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,5 @@
1
+ import { ModuleState, moduleStore } from "./commonStore";
2
+ type ModuleProviderProps = React.PropsWithChildren<Partial<moduleStore>>;
3
+ export { initialValueOrder } from "./commonStore";
4
+ export declare function ModuleProvider({ children, ...props }: ModuleProviderProps): import("react/jsx-runtime").JSX.Element;
5
+ export declare function useModuleContext<T>(selector: (state: ModuleState) => T): T;
@@ -0,0 +1,56 @@
1
+ export declare const goodListIntialValue: {
2
+ dataPic: string;
3
+ goodsName: string;
4
+ goodsCamount: number;
5
+ skuName: string;
6
+ pricesetNprice: number;
7
+ };
8
+ export declare const initialValueOrder: {
9
+ contractSettlOpno: number;
10
+ upmMap: {};
11
+ rebMoney: number;
12
+ goodsCamount: number;
13
+ shoppingCountPrice: number;
14
+ totalDiscountPrice: number;
15
+ accountsSumPrice: number;
16
+ discount: number;
17
+ freight: number;
18
+ comDisMoney: number;
19
+ copyComDisMoney: number;
20
+ shoppingType: string;
21
+ promotionCode: string;
22
+ promotionCodes: string;
23
+ };
24
+ export type addressInfo = {
25
+ freight: number;
26
+ goodsReceiptMem: string;
27
+ goodsReceiptPhone: string;
28
+ goodsReceiptArrdess: string;
29
+ areaCode: string;
30
+ };
31
+ export type moduleType = {
32
+ [v: string]: any;
33
+ _ocPoints: Array<any>;
34
+ _ocDiscount: Array<any>;
35
+ _orderAddressInfo: addressInfo;
36
+ _couponList: [];
37
+ _selectCoupon: [];
38
+ _shoppingList: Array<any>;
39
+ _contractGoodsList: Array<typeof goodListIntialValue>;
40
+ _orderDomainStr: Array<typeof initialValueOrder>;
41
+ _ocContractSettlList: Array<any>;
42
+ open?: boolean;
43
+ defaultValue?: object;
44
+ goodNum?: number;
45
+ _skuInfo?: object;
46
+ params?: object;
47
+ breadList?: [];
48
+ };
49
+ export interface moduleStore {
50
+ moduleStore: moduleType;
51
+ }
52
+ export interface ModuleState extends moduleStore {
53
+ setModuleStore: (e: Partial<moduleType>) => void;
54
+ }
55
+ export type ModuleStore = ReturnType<typeof createModuleStore>;
56
+ export declare const createModuleStore: (initProps?: Partial<moduleStore>) => import("zustand").StoreApi<ModuleState>;
package/package.json CHANGED
@@ -1,8 +1,8 @@
1
1
  {
2
2
  "name": "@brushes/context",
3
- "version": "0.0.6",
3
+ "version": "0.0.7",
4
4
  "description": "",
5
- "main": "src/index.ts",
5
+ "main": "dist/index.js",
6
6
  "scripts": {
7
7
  "start": "rollup -c --watch",
8
8
  "build": "./scripts/build.sh"
@@ -1,46 +0,0 @@
1
- import {
2
- ModuleStore,
3
- createModuleStore,
4
- ModuleState,
5
- moduleStore,
6
- } from "./commonStore";
7
- import { useRef, useContext, createContext } from "react";
8
- import { useStore } from "zustand";
9
- const ModuleContext = createContext<ModuleStore | null>(null);
10
-
11
- type ModuleProviderProps = React.PropsWithChildren<Partial<moduleStore>>;
12
-
13
- export { initialValueOrder } from "./commonStore";
14
-
15
- // Provider wrapper
16
- export function ModuleProvider({ children, ...props }: ModuleProviderProps) {
17
- const storeRef = useRef<ModuleStore>();
18
-
19
- if (!storeRef.current) {
20
- storeRef.current = createModuleStore(props);
21
- }
22
- return (
23
- <ModuleContext.Provider value={storeRef.current}>
24
- {children}
25
- </ModuleContext.Provider>
26
- );
27
- }
28
-
29
- export function useModuleContext<T>(selector: (state: ModuleState) => T): T {
30
- const store = useContext(ModuleContext);
31
- if (!store) throw new Error("Missing ModuleContext.Provider in the tree");
32
- return useStore(store, selector);
33
- }
34
-
35
- // example
36
- // Consumer usage of the custom hook
37
- // function CommonConsumer() {
38
- // const module_id = useModuleContext((s) => s.module_id)
39
- // const setModuleId = useModuleContext((s) => s.setModuleId)
40
- // return (
41
- // <>
42
- // <div>{module_id} Bears.</div>
43
- // <button onClick={setModuleId}>Add bear</button>
44
- // </>
45
- // )
46
- // }
@@ -1,103 +0,0 @@
1
- import { createStore } from "zustand";
2
-
3
- export const goodListIntialValue = {
4
- dataPic: "",
5
- goodsName: "",
6
- goodsCamount: 0,
7
- skuName: "",
8
- pricesetNprice: 0,
9
- };
10
-
11
- export const initialValueOrder = {
12
- contractSettlOpno: 0,
13
- upmMap: {},
14
- rebMoney: 0,
15
- goodsCamount: 0,
16
- shoppingCountPrice: 0,
17
- totalDiscountPrice: 0,
18
- accountsSumPrice: 0,
19
- discount: 0,
20
- freight: 0,
21
- comDisMoney: 0,
22
- copyComDisMoney: 0,
23
- shoppingType: "",
24
- promotionCode: "",
25
- promotionCodes: "",
26
- };
27
-
28
- export type addressInfo = {
29
- freight: number;
30
- goodsReceiptMem: string;
31
- goodsReceiptPhone: string;
32
- goodsReceiptArrdess: string;
33
- areaCode: string;
34
- };
35
-
36
- export type moduleType = {
37
- [v: string]: any;
38
- _ocPoints: Array<any>;
39
- _ocDiscount: Array<any>;
40
- _orderAddressInfo: addressInfo;
41
- _couponList: []; // 订单优惠券列表
42
- _selectCoupon: []; // 选中的优惠券
43
- _shoppingList: Array<any>; // 订单商品信息
44
- _contractGoodsList: Array<typeof goodListIntialValue>; // 确认订单支付模块
45
- _orderDomainStr: Array<typeof initialValueOrder>; // 确认订单支付模块
46
- _ocContractSettlList: Array<any>; // 确认订单支付模块
47
- open?: boolean; //抽屉展示或掩藏
48
- defaultValue?: object; // 页面模块默认值
49
- goodNum?: number; // 选择商品数量
50
- _skuInfo?: object; // sku商品数据
51
- params?: object; //每个模块的请求参数
52
- breadList?: []; //面包屑
53
- };
54
-
55
- export interface moduleStore {
56
- // module_id?: number;
57
- // current?: number;
58
- // hotelParams?: object;
59
- // extraParams?: object; //每个模块的扩展参数
60
- // title?: string;
61
- moduleStore: moduleType;
62
- }
63
-
64
- export interface ModuleState extends moduleStore {
65
- setModuleStore: (e: Partial<moduleType>) => void;
66
- }
67
-
68
- export type ModuleStore = ReturnType<typeof createModuleStore>;
69
-
70
- export const createModuleStore = (initProps?: Partial<moduleStore>) => {
71
- const DEFAULT_PROPS: moduleStore = {
72
- moduleStore: {
73
- _ocDiscount: [],
74
- _ocPoints: [],
75
- _couponList: [],
76
- _selectCoupon: [], // 选中的优惠券
77
- _shoppingList: [], // 订单商品信息
78
- _contractGoodsList: [],
79
- _orderDomainStr: [],
80
- _ocContractSettlList: [],
81
- _orderAddressInfo: {
82
- freight: 0,
83
- goodsReceiptMem: "",
84
- goodsReceiptPhone: "",
85
- goodsReceiptArrdess: "",
86
- areaCode: "",
87
- },
88
- defaultValue: void 0,
89
- _skuInfo: {},
90
- params: {},
91
- breadList: [],
92
- open: false,
93
- },
94
- };
95
- return createStore<ModuleState>()((set) => ({
96
- ...DEFAULT_PROPS,
97
- ...initProps,
98
- setModuleStore: (store) =>
99
- set((state) => {
100
- return { moduleStore: Object.assign(state.moduleStore, store) };
101
- }),
102
- }));
103
- };
@@ -1,40 +0,0 @@
1
- import {
2
- ModuleRootStore,
3
- createRootModuleStore,
4
- ModuleRootState,
5
- moduleRootStore,
6
- } from "./rootStore";
7
- import { useRef, useContext, createContext } from "react";
8
- import { useStore } from "zustand";
9
-
10
- export { initPersist } from "./rootStore";
11
-
12
- const ModuleContext = createContext<ModuleRootStore | null>(null);
13
-
14
- type ModuleProviderProps = React.PropsWithChildren<Partial<moduleRootStore>>;
15
-
16
- // Provider wrapper
17
- export function ModuleRootProvider({
18
- children,
19
- ...props
20
- }: ModuleProviderProps) {
21
- const storeRef = useRef<ModuleRootStore>();
22
-
23
- if (!storeRef.current) {
24
- storeRef.current = createRootModuleStore(props);
25
- }
26
-
27
- return (
28
- <ModuleContext.Provider value={storeRef.current}>
29
- {children}
30
- </ModuleContext.Provider>
31
- );
32
- }
33
-
34
- export function useModuleRootContext<T>(
35
- selector: (state: ModuleRootState) => T,
36
- ): T {
37
- const store = useContext(ModuleContext);
38
- if (!store) throw new Error("Missing RootModuleContext.Provider in the tree");
39
- return useStore(store, selector);
40
- }
@@ -1,91 +0,0 @@
1
- import { createStore } from "zustand";
2
- import { persist, createJSONStorage } from "zustand/middleware";
3
-
4
- let localStorageImpl: any = localStorage;
5
-
6
- export const initPersist = (Taro: any) => {
7
- if (Taro) {
8
- localStorageImpl = {
9
- getItem: (key: string) => {
10
- try {
11
- const value = Taro.getStorageSync(key);
12
- return value !== "" ? value : null;
13
- } catch (error) {
14
- console.error(`读取存储失败 [${key}]`, error);
15
- return null;
16
- }
17
- },
18
- setItem: (key: string, value: any) => {
19
- try {
20
- Taro.setStorageSync(key, value);
21
- } catch (error) {
22
- console.error(`写入存储失败 [${key}]`, error);
23
- }
24
- },
25
- removeItem: (key: string) => {
26
- try {
27
- Taro.removeStorageSync(key);
28
- } catch (error) {
29
- console.error(`删除存储失败 [${key}]`, error);
30
- }
31
- },
32
- };
33
- }
34
- };
35
-
36
- export type moduleType = {
37
- [v: string]: any;
38
- safe?: number;
39
- _historyList: Array<any>;
40
- _themeColor: { colorPrimary: string; colorBgTextHover: string };
41
- _orderCount: { [v: string]: string | number }; // 订单角标
42
- _userInfo: { [v: string]: any }; // 用户信息
43
- _cart: number; // 购物车数据
44
- };
45
-
46
- export interface moduleRootStore {
47
- // module_id?: number;
48
- // current?: number;
49
- // hotelParams?: object;
50
- // extraParams?: object; //每个模块的扩展参数
51
- // title?: string;
52
- rootStore: moduleType;
53
- [v: string]: any;
54
- }
55
-
56
- export interface ModuleRootState extends moduleRootStore {
57
- setModuleRootStore: (e: Partial<moduleType>) => void;
58
- }
59
-
60
- export type ModuleRootStore = ReturnType<typeof createRootModuleStore>;
61
-
62
- export const createRootModuleStore = (initProps?: Partial<moduleRootStore>) => {
63
- const DEFAULT_PROPS: moduleRootStore = {
64
- rootStore: {
65
- safe: 0,
66
- _userInfo: {},
67
- _historyList: [],
68
- _themeColor: { colorPrimary: "#1677ff", colorBgTextHover: "#e6r4ff" },
69
- _orderCount: {},
70
- _cart: 0,
71
- _webStore: {},
72
- _menuChildren: [],
73
- },
74
- };
75
- return createStore<ModuleRootState>()(
76
- persist(
77
- (set) => ({
78
- ...DEFAULT_PROPS,
79
- ...initProps,
80
- setModuleRootStore: (store) =>
81
- set((state) => {
82
- return { rootStore: Object.assign(state.rootStore, store) };
83
- }),
84
- }),
85
- {
86
- name: "root-storage", // 存储的 key 名
87
- storage: createJSONStorage(() => localStorageImpl), // (optional) by default, 'localStorage' is used
88
- },
89
- ),
90
- );
91
- };
File without changes
File without changes