From eaa4eafc1aa0c432aa0a74462563bb6824a9ef8e Mon Sep 17 00:00:00 2001 From: Benno Kohrs Date: Fri, 9 Jul 2021 17:21:38 +0200 Subject: [PATCH] added deps array to useAgile --- .../computed/bench/agilets/autoTracking.tsx | 3 ++- .../computed/bench/agilets/hardCoded.tsx | 3 ++- examples/react/release/boxes/package.json | 5 ++-- .../src/components/EditProperties/index.tsx | 4 +-- examples/react/release/boxes/src/core/app.ts | 10 ++++---- examples/react/release/boxes/yarn.lock | 25 ++++++++----------- packages/react/src/hooks/useAgile.ts | 12 ++++++++- 7 files changed, 36 insertions(+), 26 deletions(-) diff --git a/benchmark/benchmarks/react/computed/bench/agilets/autoTracking.tsx b/benchmark/benchmarks/react/computed/bench/agilets/autoTracking.tsx index df85d176..0b596405 100644 --- a/benchmark/benchmarks/react/computed/bench/agilets/autoTracking.tsx +++ b/benchmark/benchmarks/react/computed/bench/agilets/autoTracking.tsx @@ -1,8 +1,9 @@ import React from 'react'; import ReactDom from 'react-dom'; -import { createComputed, createState } from '@agile-ts/core'; +import { createComputed, createState, LogCodeManager } from '@agile-ts/core'; import { useAgile } from '@agile-ts/react'; +LogCodeManager.getLogger().isActive = false; const COUNT = createState(0); const COMPUTED_COUNT = createComputed(() => { return COUNT.value * 5; diff --git a/benchmark/benchmarks/react/computed/bench/agilets/hardCoded.tsx b/benchmark/benchmarks/react/computed/bench/agilets/hardCoded.tsx index ac782b55..59cc57a8 100644 --- a/benchmark/benchmarks/react/computed/bench/agilets/hardCoded.tsx +++ b/benchmark/benchmarks/react/computed/bench/agilets/hardCoded.tsx @@ -1,8 +1,9 @@ import React from 'react'; import ReactDom from 'react-dom'; -import { createComputed, createState } from '@agile-ts/core'; +import { createComputed, createState, LogCodeManager } from '@agile-ts/core'; import { useAgile } from '@agile-ts/react'; +LogCodeManager.getLogger().isActive = false; const COUNT = createState(0); const COMPUTED_COUNT = createComputed( () => { diff --git a/examples/react/release/boxes/package.json b/examples/react/release/boxes/package.json index 8090cf6b..8fdd52f6 100644 --- a/examples/react/release/boxes/package.json +++ b/examples/react/release/boxes/package.json @@ -4,6 +4,7 @@ "private": true, "dependencies": { "@agile-ts/core": "file:.yalc/@agile-ts/core", + "@agile-ts/logger": "file:.yalc/@agile-ts/logger", "@agile-ts/proxytree": "file:.yalc/@agile-ts/proxytree", "@agile-ts/react": "file:.yalc/@agile-ts/react", "@chakra-ui/react": "^1.6.3", @@ -32,8 +33,8 @@ "build": "react-scripts build", "test": "react-scripts test", "eject": "react-scripts eject", - "install:dev:agile": "yalc add @agile-ts/core @agile-ts/react @agile-ts/proxytree & yarn install", - "install:prod:agile": "yarn add @agile-ts/core @agile-ts/react @agile-ts/proxytree" + "install:dev:agile": "yalc add @agile-ts/core @agile-ts/react @agile-ts/proxytree @agile-ts/logger & yarn install", + "install:prod:agile": "yarn add @agile-ts/core @agile-ts/react @agile-ts/proxytree @agile-ts/logger & yarn install" }, "eslintConfig": { "extends": [ diff --git a/examples/react/release/boxes/src/components/EditProperties/index.tsx b/examples/react/release/boxes/src/components/EditProperties/index.tsx index b1caa3cd..3729f759 100644 --- a/examples/react/release/boxes/src/components/EditProperties/index.tsx +++ b/examples/react/release/boxes/src/components/EditProperties/index.tsx @@ -136,8 +136,8 @@ const Property = ({ id: number | string; }) => { const ELEMENT = core.ui.ELEMENTS.getItem(id); - const element = useProxy(ELEMENT, { componentId: 'Property' }); - console.log('Element', ELEMENT); + const element = useProxy(ELEMENT, { componentId: 'Property', deps: [id] }); + return ( { agileInstance?.subController.unsubscribe(subscriptionContainer); }; - }, []); + }, config.deps); return getReturnValue(depsArray); } @@ -261,4 +262,13 @@ export interface AgileHookConfigInterface { * @default undefined */ observerType?: string; + /** + * Dependencies that determine, in addition to unmounting and remounting the React-Component, + * when the specified Agile Sub Instances should be re-subscribed to the React-Component. + * + * [Github issue](https://github.com/agile-ts/agile/issues/170) + * + * @default [] + */ + deps?: any[]; }