From 6147007d39a80ad456f894843ae64ee50ca200b2 Mon Sep 17 00:00:00 2001 From: * <8> Date: Fri, 29 Jul 2022 20:55:17 +0800 Subject: [PATCH 01/21] Match-id-f9ed95d7457078acdc9d7d2f4fdaf7c02d74af41 --- .../src/horizonx/adapters/reduxReact.ts | 11 +++-- .../src/horizonx/store/StoreHandler.ts | 12 ++--- .../StoreFunctionality/basicAccess.test.tsx | 45 +++++++++++++++++++ 3 files changed, 57 insertions(+), 11 deletions(-) diff --git a/libs/horizon/src/horizonx/adapters/reduxReact.ts b/libs/horizon/src/horizonx/adapters/reduxReact.ts index 8e205eb7..0954fbb3 100644 --- a/libs/horizon/src/horizonx/adapters/reduxReact.ts +++ b/libs/horizon/src/horizonx/adapters/reduxReact.ts @@ -33,12 +33,11 @@ export function createSelectorHook(context: Context): (selector?: (any) => any) return function(selector = state => state) { const [b, fr] = useState(false); - const listener = () => { - fr(!b); - }; - useEffect(() => { - return store.subscribe(listener); + const unsubscribe = store.subscribe(() => fr(!b)); + return () => { + unsubscribe(); + }; }); return selector(store.getState()); @@ -110,7 +109,7 @@ export function connect( useEffect(() => { const unsubscribe = store.subscribe(() => forceReload(!f)); - () => { + return () => { unsubscribe(); }; }); diff --git a/libs/horizon/src/horizonx/store/StoreHandler.ts b/libs/horizon/src/horizonx/store/StoreHandler.ts index ffc67aa8..ecbe22d9 100644 --- a/libs/horizon/src/horizonx/store/StoreHandler.ts +++ b/libs/horizon/src/horizonx/store/StoreHandler.ts @@ -15,7 +15,7 @@ function isPromise(obj: any): boolean { type StoreConfig, C extends UserComputedValues> = { state?: S; - options?: { suppressHooks?: boolean }; + // options?: { suppressHooks?: boolean }; actions?: A; id?: string; computed?: C; @@ -27,18 +27,18 @@ export type ReduxStoreHandler = { getState: () => any; subscribe: (listener: () => void) => () => void; replaceReducer: (reducer: (state: any, action: { type: string }) => any) => void; - _horizonXstore: StoreHandler; + // _horizonXstore: StoreHandler; }; type StoreHandler, C extends UserComputedValues> = { $subscribe: (listener: () => void) => void; $unsubscribe: (listener: () => void) => void; $s: S; - $config: StoreConfig; + // $config: StoreConfig; $queue: QueuedStoreActions; $a: StoreActions; $c: UserComputedValues; - reduxHandler?: ReduxStoreHandler; + // reduxHandler?: ReduxStoreHandler; } & { [K in keyof S]: S[K] } & { [K in keyof A]: Action } & { [K in keyof C]: ReturnType }; @@ -256,13 +256,15 @@ function hookStore() { function createStoreHook, C extends UserComputedValues>( storeHandler: StoreHandler ): () => StoreHandler { - return () => { + const storeHook = () => { if (!storeHandler.$config.options?.suppressHooks) { hookStore(); } return storeHandler; }; + + return storeHook; } export function useStore, C extends UserComputedValues>( diff --git a/scripts/__tests__/HorizonXText/StoreFunctionality/basicAccess.test.tsx b/scripts/__tests__/HorizonXText/StoreFunctionality/basicAccess.test.tsx index 0a2c8584..9d95c95f 100644 --- a/scripts/__tests__/HorizonXText/StoreFunctionality/basicAccess.test.tsx +++ b/scripts/__tests__/HorizonXText/StoreFunctionality/basicAccess.test.tsx @@ -107,4 +107,49 @@ describe('Basic store manipulation', () => { expect(document.getElementById(RESULT_ID)?.innerHTML).toBe('5'); }); + + it('should call computed from own actions', () => { + const useIncrementStore = createStore({ + id: 'incrementStore', + state: { + count: 2, + }, + actions: { + doublePlusOne: function(state) { + state.count = this.double + 1; + }, + }, + computed:{ + double: (state) => { + return state.count*2 + } + } + }); + + function App() { + const incrementStore = useIncrementStore(); + + return ( +
+ +

{incrementStore.count}

+
+ ); + } + + Horizon.render(, container); + + Horizon.act(() => { + triggerClickEvent(container, BUTTON_ID); + }); + + expect(document.getElementById(RESULT_ID)?.innerHTML).toBe('5'); + }) }); From 4120cf3c3d48aa7daa7e1cb6ef32e22c6253f621 Mon Sep 17 00:00:00 2001 From: * <8> Date: Sat, 30 Jul 2022 15:24:07 +0800 Subject: [PATCH 02/21] Match-id-dc5396d053912b31447af44751ffc75c4cd6e2e5 --- libs/horizon/src/horizonx/store/StoreHandler.ts | 4 ---- 1 file changed, 4 deletions(-) diff --git a/libs/horizon/src/horizonx/store/StoreHandler.ts b/libs/horizon/src/horizonx/store/StoreHandler.ts index ecbe22d9..e85391d8 100644 --- a/libs/horizon/src/horizonx/store/StoreHandler.ts +++ b/libs/horizon/src/horizonx/store/StoreHandler.ts @@ -15,7 +15,6 @@ function isPromise(obj: any): boolean { type StoreConfig, C extends UserComputedValues> = { state?: S; - // options?: { suppressHooks?: boolean }; actions?: A; id?: string; computed?: C; @@ -27,18 +26,15 @@ export type ReduxStoreHandler = { getState: () => any; subscribe: (listener: () => void) => () => void; replaceReducer: (reducer: (state: any, action: { type: string }) => any) => void; - // _horizonXstore: StoreHandler; }; type StoreHandler, C extends UserComputedValues> = { $subscribe: (listener: () => void) => void; $unsubscribe: (listener: () => void) => void; $s: S; - // $config: StoreConfig; $queue: QueuedStoreActions; $a: StoreActions; $c: UserComputedValues; - // reduxHandler?: ReduxStoreHandler; } & { [K in keyof S]: S[K] } & { [K in keyof A]: Action } & { [K in keyof C]: ReturnType }; From 54369ce2e0114ed95f8c76e5a02a2883abdc2b92 Mon Sep 17 00:00:00 2001 From: * <8> Date: Mon, 1 Aug 2022 17:45:36 +0800 Subject: [PATCH 03/21] Match-id-9c31e24a5544b16a0f370ecc53aeda94d4df9de4 --- .cloudbuild/CI.sh | 2 ++ .cloudbuild/build.yml | 33 +++++++++++++++++++ .cloudbuild/tag.yml | 30 +++++++++++++++++ .../__snapshots__/DomTextarea.test.js.snap | 5 --- 4 files changed, 65 insertions(+), 5 deletions(-) create mode 100644 .cloudbuild/CI.sh create mode 100644 .cloudbuild/build.yml create mode 100644 .cloudbuild/tag.yml delete mode 100644 scripts/__tests__/DomTest/__snapshots__/DomTextarea.test.js.snap diff --git a/.cloudbuild/CI.sh b/.cloudbuild/CI.sh new file mode 100644 index 00000000..7972c069 --- /dev/null +++ b/.cloudbuild/CI.sh @@ -0,0 +1,2 @@ +yarn +yarn run test diff --git a/.cloudbuild/build.yml b/.cloudbuild/build.yml new file mode 100644 index 00000000..01ece498 --- /dev/null +++ b/.cloudbuild/build.yml @@ -0,0 +1,33 @@ +version: '2.0' +notifications: + notifier: + espace: + 'on': false + email: + 'on': false +buildspace: + log_collect: + - config/CI/build/logs + fixed: true +env: + resource: + type: docker + image: kweecr04.his.huawei.com:80/ecr-build-arm-gzkunpeng/euleros_v2r7spc522_x64_opmt_cs5.0_sz:v5.0 + class: 4U8G + mode: toolbox + cache: + - type: workspace +steps: + PRE_BUILD: + - checkout + - gitlab: + url: https://szv-y.codehub.huawei.com/CloudSOP/CloudSOP-CI.git + branch: $branch + path: CI + BUILD: + - build_execute: + command: | + npm install yarn -g + yarn config set strict-ssl false + yarn + yarn run test diff --git a/.cloudbuild/tag.yml b/.cloudbuild/tag.yml new file mode 100644 index 00000000..4b562f49 --- /dev/null +++ b/.cloudbuild/tag.yml @@ -0,0 +1,30 @@ +version: '2.0' +notifications: + notifier: + espace: + 'on': false + email: + 'on': false +buildspace: + log_collect: + - config/CI/build/logs + fixed: true +env: + resource: + type: docker + image: kweecr04.his.huawei.com:80/ecr-build-arm-gzkunpeng/euleros_v2r7spc522_x64_opmt_cs5.0_sz:v5.0 + class: 4U8G + mode: toolbox + cache: + - type: workspace +steps: + PRE_BUILD: + - checkout + - gitlab: + url: https://szv-y.codehub.huawei.com/CloudSOP/CloudSOP-CI.git + branch: $branch + path: CI + BUILD: + - build_execute: + command: | + git tag $releaseVersion diff --git a/scripts/__tests__/DomTest/__snapshots__/DomTextarea.test.js.snap b/scripts/__tests__/DomTest/__snapshots__/DomTextarea.test.js.snap deleted file mode 100644 index c2975807..00000000 --- a/scripts/__tests__/DomTest/__snapshots__/DomTextarea.test.js.snap +++ /dev/null @@ -1,5 +0,0 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP - -exports[`Dom Textarea should not incur unnecessary DOM mutations 1`] = `