@brushes/context 0.0.3 → 0.0.5
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.
- package/dist/index.js +1 -1
- package/dist/store/rootStore.d.ts +1 -0
- package/package.json +1 -1
- package/rollup.config.js +1 -1
- package/src/store/rootStore.tsx +30 -30
- package/dist/index.d.ts +0 -1
- package/dist/store/commonModule.d.ts +0 -5
- package/dist/store/commonStore.d.ts +0 -56
- package/dist/store/index.d.ts +0 -2
- package/dist/store/rootModule.d.ts +0 -5
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{jsx as o}from"react/jsx-runtime";import{createStore as
|
|
1
|
+
import{jsx as o}from"react/jsx-runtime";import{createStore as e,useStore as r}from"zustand";import{createContext as t,useRef as n,useContext as s}from"react";import{persist as i,createJSONStorage as c}from"zustand/middleware";function u(o,e){var r={};for(var t in o)Object.prototype.hasOwnProperty.call(o,t)&&e.indexOf(t)<0&&(r[t]=o[t]);if(null!=o&&"function"==typeof Object.getOwnPropertySymbols){var n=0;for(t=Object.getOwnPropertySymbols(o);n<t.length;n++)e.indexOf(t[n])<0&&Object.prototype.propertyIsEnumerable.call(o,t[n])&&(r[t[n]]=o[t[n]])}return r}"function"==typeof SuppressedError&&SuppressedError;const a={contractSettlOpno:0,upmMap:{},rebMoney:0,goodsCamount:0,shoppingCountPrice:0,totalDiscountPrice:0,accountsSumPrice:0,discount:0,freight:0,comDisMoney:0,copyComDisMoney:0,shoppingType:"",promotionCode:"",promotionCodes:""},d=t(null);function l(r){var{children:t}=r,s=u(r,["children"]);const i=n();return i.current||(i.current=(o=>{const r={moduleStore:{_ocDiscount:[],_ocPoints:[],_couponList:[],_selectCoupon:[],_shoppingList:[],_contractGoodsList:[],_orderDomainStr:[],_ocContractSettlList:[],_orderAddressInfo:{freight:0,goodsReceiptMem:"",goodsReceiptPhone:"",goodsReceiptArrdess:"",areaCode:""},defaultValue:void 0,_skuInfo:{},params:{},breadList:[],open:!1}};return e()(e=>Object.assign(Object.assign(Object.assign({},r),o),{setModuleStore:o=>e(e=>({moduleStore:Object.assign(e.moduleStore,o)}))}))})(s)),o(d.Provider,{value:i.current,children:t})}function p(o){const e=s(d);if(!e)throw new Error("Missing ModuleContext.Provider in the tree");return r(e,o)}let f=localStorage;const m=t(null);function g(r){var{children:t}=r,s=u(r,["children"]);const a=n();return a.current||(a.current=(o=>{const r={rootStore:{safe:0,_userInfo:{},_historyList:[],_themeColor:{colorPrimary:"#1677ff",colorBgTextHover:"#e6r4ff"},_orderCount:{},_cart:0,_webStore:{},_menuChildren:[]}};return e()(i(e=>Object.assign(Object.assign(Object.assign({},r),o),{setModuleRootStore:o=>e(e=>({rootStore:Object.assign(e.rootStore,o)}))}),{name:"root-storage",storage:c(()=>f)}))})(s)),o(m.Provider,{value:a.current,children:t})}function h(o){const e=s(m);if(!e)throw new Error("Missing RootModuleContext.Provider in the tree");return r(e,o)}export{l as ModuleProvider,g as ModuleRootProvider,a as initialValueOrder,p as useModuleContext,h as useModuleRootContext};
|
package/package.json
CHANGED
package/rollup.config.js
CHANGED
|
@@ -10,6 +10,6 @@ export default {
|
|
|
10
10
|
}
|
|
11
11
|
],
|
|
12
12
|
cache: false,
|
|
13
|
-
external: ['react/jsx-runtime', 'zustand', 'react', 'zustand/middleware', '@brushes/utils'],
|
|
13
|
+
external: ['react/jsx-runtime', 'zustand', 'react', 'zustand/middleware', '@brushes/utils', '@brushes/component-tool'],
|
|
14
14
|
plugins: [ts({}), terser()]
|
|
15
15
|
};
|
package/src/store/rootStore.tsx
CHANGED
|
@@ -1,34 +1,36 @@
|
|
|
1
1
|
import { createStore } from "zustand";
|
|
2
2
|
import { persist, createJSONStorage } from "zustand/middleware";
|
|
3
|
-
import { getEnv, getTaro } from "@brushes/utils";
|
|
4
3
|
|
|
5
|
-
|
|
6
|
-
const Taro = getTaro();
|
|
4
|
+
let localStorageImpl: any = localStorage;
|
|
7
5
|
|
|
8
|
-
const
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
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
|
+
}
|
|
32
34
|
};
|
|
33
35
|
|
|
34
36
|
export type moduleType = {
|
|
@@ -82,9 +84,7 @@ export const createRootModuleStore = (initProps?: Partial<moduleRootStore>) => {
|
|
|
82
84
|
}),
|
|
83
85
|
{
|
|
84
86
|
name: "root-storage", // 存储的 key 名
|
|
85
|
-
storage: createJSONStorage(() =>
|
|
86
|
-
isTaro ? miniProgramStorage : localStorage,
|
|
87
|
-
), // (optional) by default, 'localStorage' is used
|
|
87
|
+
storage: createJSONStorage(() => localStorageImpl), // (optional) by default, 'localStorage' is used
|
|
88
88
|
},
|
|
89
89
|
),
|
|
90
90
|
);
|
package/dist/index.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from "./store";
|
|
@@ -1,5 +0,0 @@
|
|
|
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;
|
|
@@ -1,56 +0,0 @@
|
|
|
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/dist/store/index.d.ts
DELETED
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
import { ModuleRootState, moduleRootStore } from "./rootStore";
|
|
2
|
-
type ModuleProviderProps = React.PropsWithChildren<Partial<moduleRootStore>>;
|
|
3
|
-
export declare function ModuleRootProvider({ children, ...props }: ModuleProviderProps): import("react/jsx-runtime").JSX.Element;
|
|
4
|
-
export declare function useModuleRootContext<T>(selector: (state: ModuleRootState) => T): T;
|
|
5
|
-
export {};
|