@@ -952,6 +952,81 @@ describe("本地Store同步", () => {
952952 return moduleStore ;
953953 } ) ;
954954
955+ setTimeout ( ( ) => {
956+ resolve ( ) ;
957+ // expect(toStore.state).toEqual({
958+ // myorder: {
959+ // "order.c": 2,
960+ // },
961+ // });
962+
963+ // expect(toStore.schemas.has(["myorder", "order.c"])).toBeTruthy();
964+ // toStore.schemas.store.on("computed:done", ({ path, value }) => {
965+ // // console.log("computed:done", path, value);
966+ // resolve();
967+ // });
968+ // //
969+ // toStore.schemas.get(["myorder", "order.c"] as never)!.select;
970+ } ) ;
971+ } ) ;
972+ } ) ;
973+ test ( "多对一同步配置时的初始化事件" , ( ) => {
974+ const toStore = new AutoStore (
975+ { } ,
976+ {
977+ id : "to" ,
978+ } ,
979+ ) ;
980+ toStore . watch ( ( operate ) => {
981+ if ( operate . flags ! < 0 ) return ;
982+ if ( operate . type === "set" ) {
983+ console . log ( "toStore.watch" , operate . path , operate . value ) ;
984+ }
985+ } ) ;
986+
987+ return new Promise < void > ( ( resolve ) => {
988+ // order.a <-> myorder['order.a']
989+ const moduleStores = Array . from ( { length : 1 } , ( _ , i ) => {
990+ const id = `module${ i + 1 } ` ;
991+ const moduleStore = new AutoStore (
992+ {
993+ // count: configurable(100, {
994+ // label: "数量",
995+ // }),
996+ // price: configurable(100, {
997+ // label: "姓名",
998+ // }),
999+ tags : configurable ( [ ] , {
1000+ label : "标签" ,
1001+ } ) ,
1002+ } ,
1003+ { id } ,
1004+ ) ;
1005+
1006+ moduleStore . sync ( toStore , {
1007+ remote : id ,
1008+ immediate : true ,
1009+ filter : ( path : string [ ] ) => {
1010+ return moduleStore . schemas . has ( path . join ( "." ) as any ) ;
1011+ } ,
1012+ pathMap : {
1013+ toRemote : ( path : string [ ] , value ) => {
1014+ // 重点:如果值是对象但使用configurable包装的,则不进行路径转换,否则会导致无法正确同步数据
1015+ if ( typeof value !== "object" || moduleStore . schemas . has ( path as any ) ) {
1016+ return [ path . join ( "." ) ] ;
1017+ }
1018+ } ,
1019+ toLocal : ( path : string [ ] ) => {
1020+ return path . reduce < string [ ] > ( ( result , cur ) => {
1021+ result . push ( ...cur . split ( "." ) ) ;
1022+ return result ;
1023+ } , [ ] ) ;
1024+ } ,
1025+ } ,
1026+ } ) ;
1027+ return moduleStore ;
1028+ } ) ;
1029+
9551030 setTimeout ( ( ) => {
9561031 resolve ( ) ;
9571032 // expect(toStore.state).toEqual({
0 commit comments