Skip to content
This repository was archived by the owner on Oct 16, 2024. It is now read-only.

Commit f168baf

Browse files
committed
deprecated useOutput
1 parent f6df666 commit f168baf

File tree

7 files changed

+67
-100
lines changed

7 files changed

+67
-100
lines changed

packages/react/README.md

Lines changed: 25 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<img src="https://raw.githubusercontent.com/agile-ts/agile/master/packages/react/static/header_background.png" alt="React Integration">
22

3-
> Integrate AgileTs into React or React-Native
3+
> Integration for React and React-Native
44
55
<br />
66

@@ -20,43 +20,46 @@
2020
<br />
2121
<img src="https://raw.githubusercontent.com/agile-ts/agile/master/packages/react/static/what_does_this_integration_header.png" alt="What does this Integration?"/>
2222

23-
The `react` package helps us to integrate AgileTs into a [React](https://reactjs.org/) environment
24-
and serves as an Interface to React.
25-
Its main task is to bind States to React Components.
26-
This binding ensures that AgileTs rerender the Component whenever a bound State mutates.
27-
It also offers some other valuable functionalities that optimize the workflow using AgileTs in a React project.
23+
The `react` package is a set of utilities that simplifies the way AgileTs is integrated into a [React](https://reactjs.org/) environment.
24+
Think of it as an extension of AgileTs in the context of React
25+
that serves as an interface to React Components.
26+
The main task of the `react` integration is to bind AgileTs States to React Components.
27+
This ensures that AgileTs will re-render the Component when the bound State changes.
28+
It also provides some other valuable functionalities
29+
that optimize the workflow with AgileTs in a React project.
2830

29-
A distinction is made between `Functional` and `Class` Components.
30-
As we prefer to use [`React Hooks`](https://reactjs.org/docs/hooks-intro.html) in Functional Components
31-
but Hooks aren't supported in Class Components.
32-
Therefore, we have created alternatives for Class Components in order to offer the same functionalities there as well.
31+
A distinction is made between `Functional` and `Class` React Components.
32+
As we prefer to use [`React Hooks`](https://reactjs.org/docs/hooks-intro.html) in Functional Components,
33+
however, Hooks aren't supported in Class Components.
34+
Therefore, we have created alternatives for Class Components
35+
in order to offer the most essential functionalities there as well.
3336

3437
### 🐆 Functional Component
35-
In Functional Components we recommend using AgileTs Hooks like [`useAgile()`](https://agile-ts.org/docs/react/hooks/#useagile).
38+
In `Functional Components` we recommend using AgileTs Hooks like [`useAgile()`](https://agile-ts.org/docs/react/hooks/#useagile).
3639
The `useAgile()` Hook binds [Agile Sub Instances](https://agile-ts.org/docs/introduction#agile-sub-instance)
37-
(like States or Collections) to React Components.
40+
(like States or Collections) to React Components for reactivity.
3841
```ts
39-
// -- myComponent.jsx ------------------------------------------
42+
// -- MyComponent.jsx ------------------------------------------
4043

41-
// Binds MY_FIRST_STATE to myComponent
44+
// Binds MY_FIRST_STATE to 'MyComponent.jsx' for reactivity
4245
const myFirstState = useAgile(MY_FIRST_STATE);
4346
```
4447
To find out more about `useAgile()`, and other Hooks provided by AgileTs,
4548
checkout the [AgileTs Hook documentation](https://agile-ts.org/docs/react/hooks).
4649

4750
### 🦖 Class Component
48-
For Class Components, we provide the `AgileHOC`.
51+
For `Class Components`, we provide the `AgileHOC`.
4952
The `AgileHOC` is a Higher Order Component that is wrapped around a React Component.
50-
It takes care of binding [Agile Sub Instances](https://agile-ts.org/docs/introduction#agile-sub-instance)
51-
(like States or Collections) to the wrapped React Component.
53+
It takes care of binding [Agile Sub Instances](https://agile-ts.org/docs/introduction#agile-sub-instance)
54+
(like States or Collections) to the wrapped React Components for reactivity.
5255
```ts
53-
// -- myComponent.jsx ------------------------------------------
56+
// -- MyComponent.jsx ------------------------------------------
5457

55-
// Binds MY_FIRST_STATE to myComponent
58+
// Binds MY_FIRST_STATE to 'MyComponent.jsx' for reactivyty
5659
export default AgileHOC(myComponent, [MY_FIRST_STATE]);
5760
```
58-
To find out more about the `AgileHOC` and AgileTs in Class Components,
59-
checkout the [AgileHOC documentation](https://agile-ts.org/docs/react/AgileHOC).
61+
To find out more about the `AgileHOC` and how to correctly use AgileTs in Class Components,
62+
take a look at the [AgileHOC documentation](https://agile-ts.org/docs/react/AgileHOC).
6063

6164

6265
<br />
@@ -75,7 +78,7 @@ Therefore, we have created a table that shows which versions fit together withou
7578

7679
| @agile-ts/react | @agile-ts/core | NPM Version | Supported React versions | Supports hook based components |
7780
| ---------------- | ----------------------- | ------------------------ | -------------------------|---------------------------------- |
78-
| v0.1.1+ | v0.1.1+ | v6+ | 16.8+ | Yes |
81+
| v0.1.2+ | v0.1.2+ | v6+ | 16.8+ | Yes |
7982

8083
_Older Versions aren't supported anymore_
8184

packages/react/src/hooks/useAgile.ts

Lines changed: 36 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@ import {
1616
LogCodeManager,
1717
normalizeArray,
1818
defineConfig,
19+
Group,
1920
} from '@agile-ts/core';
2021
import { useIsomorphicLayoutEffect } from './useIsomorphicLayoutEffect';
21-
import { AgileOutputHookArrayType, AgileOutputHookType } from './useOutput';
2222

2323
// TODO https://stackoverflow.com/questions/68148235/require-module-inside-a-function-doesnt-work
2424
let proxyPackage: any = null;
@@ -241,15 +241,15 @@ export interface AgileHookConfigInterface {
241241
* Equality comparison function
242242
* that allows you to customize the way the selected Agile Instance
243243
* is compared to determine whether the Component needs to be re-rendered.
244+
*
245+
* * Note that setting this property can destroy the useAgile type.
246+
* -> should only be used internal!
247+
*
244248
* @default undefined
245249
*/
246250
selector?: SelectorMethodType;
247251
/**
248252
* Key/Name identifier of the UI-Component the Subscription Container is bound to.
249-
*
250-
* Note that setting this property can destroy the useAgile type.
251-
* -> should only be used internal!
252-
*
253253
* @default undefined
254254
*/
255255
componentId?: ComponentIdType;
@@ -272,3 +272,34 @@ export interface AgileHookConfigInterface {
272272
*/
273273
deps?: any[];
274274
}
275+
276+
// Array Type
277+
// https://www.typescriptlang.org/docs/handbook/release-notes/typescript-2-1.html
278+
export type AgileOutputHookArrayType<T> = {
279+
[K in keyof T]: T[K] extends Collection<infer U> | Group<infer U>
280+
? U[]
281+
: T[K] extends State<infer U> | Observer<infer U>
282+
? U
283+
: T[K] extends undefined
284+
? undefined
285+
: T[K] extends Collection<infer U> | Group<infer U> | undefined
286+
? U[] | undefined
287+
: T[K] extends State<infer U> | Observer<infer U> | undefined
288+
? U | undefined
289+
: never;
290+
};
291+
292+
// No Array Type
293+
export type AgileOutputHookType<T> = T extends
294+
| Collection<infer U>
295+
| Group<infer U>
296+
? U[]
297+
: T extends State<infer U> | Observer<infer U>
298+
? U
299+
: T extends undefined
300+
? undefined
301+
: T extends Collection<infer U> | Group<infer U> | undefined
302+
? U[] | undefined
303+
: T extends State<infer U> | Observer<infer U> | undefined
304+
? U | undefined
305+
: never;

packages/react/src/hooks/useOutput.ts

Lines changed: 0 additions & 66 deletions
This file was deleted.

packages/react/src/hooks/useProxy.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@ import {
22
AgileHookConfigInterface,
33
SubscribableAgileInstancesType,
44
useAgile,
5+
AgileOutputHookArrayType,
6+
AgileOutputHookType,
57
} from './useAgile';
6-
import { AgileOutputHookArrayType, AgileOutputHookType } from './useOutput';
78
import { defineConfig } from '@agile-ts/core';
89

910
export function useProxy<X extends Array<SubscribableAgileInstancesType>>(

packages/react/src/hooks/useSelector.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,13 @@ export function useSelector<
1111
X extends SubscribableAgileInstancesType,
1212
ValueType extends AgileValueHookType<X>
1313
>(
14-
deps: X,
14+
dep: X,
1515
selector: SelectorMethodType<ValueType>,
1616
config?: AgileHookConfigInterface
1717
): ReturnType;
1818

1919
export function useSelector<ValueType = any, ReturnType = any>(
20-
deps: SubscribableAgileInstancesType,
20+
dep: SubscribableAgileInstancesType,
2121
selector: SelectorMethodType<ValueType>,
2222
config?: AgileHookConfigInterface
2323
): ReturnType;
@@ -27,12 +27,12 @@ export function useSelector<
2727
ValueType extends AgileValueHookType<X>,
2828
ReturnType = any
2929
>(
30-
deps: X,
30+
dep: X,
3131
selector: SelectorMethodType<ValueType>,
3232
config: AgileHookConfigInterface = {}
3333
): ReturnType {
3434
return useAgile(
35-
deps as any,
35+
dep as any,
3636
defineConfig(config, {
3737
selector: selector,
3838
})

packages/react/src/index.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ export { useAgile } from './hooks/useAgile';
44
export { AgileHOC } from './hocs/AgileHOC';
55
export { useWatcher } from './hooks/useWatcher';
66
export { useProxy } from './hooks/useProxy';
7-
export { useOutput } from './hooks/useOutput';
87
export { useValue } from './hooks/useValue';
98
export { useSelector } from './hooks/useSelector';
109

packages/react/tests/old/useAgile.spec.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,5 @@ const myCollection11 = useAgile(
4848
);
4949
5050
const myGroupValue = useValue(MY_COLLECTION.getGroup('test'));
51-
const myGroupOutput = useOutput(MY_COLLECTION.getGroup('test'));
5251
const myGroupAgile = useAgile(MY_COLLECTION.getGroup('test'));
5352
*/

0 commit comments

Comments
 (0)