|
1 | | -import { defineConfig } from '@agile-ts/utils'; |
2 | | -import { CreateAgileSubInstanceInterface, shared } from '../shared'; |
3 | | -import { |
4 | | - Computed, |
5 | | - ComputeFunctionType, |
6 | | - CreateComputedConfigInterface, |
7 | | - DependableAgileInstancesType, |
8 | | -} from './computed'; |
9 | | - |
10 | 1 | export * from './computed'; |
11 | 2 | export * from './computed.tracker'; |
12 | 3 |
|
13 | | -/** |
14 | | - * Returns a newly created Computed. |
15 | | - * |
16 | | - * A Computed is an extension of the State Class |
17 | | - * that computes its value based on a specified compute function. |
18 | | - * |
19 | | - * The computed value will be cached to avoid unnecessary recomputes |
20 | | - * and is only recomputed when one of its direct dependencies changes. |
21 | | - * |
22 | | - * Direct dependencies can be States and Collections. |
23 | | - * So when, for example, a dependent State value changes, the computed value is recomputed. |
24 | | - * |
25 | | - * [Learn more..](https://agile-ts.org/docs/core/agile-instance/methods#createcomputed) |
26 | | - * |
27 | | - * @public |
28 | | - * @param computeFunction - Function to compute the computed value. |
29 | | - * @param config - Configuration object |
30 | | - */ |
31 | | -export function createComputed<ComputedValueType = any>( |
32 | | - computeFunction: ComputeFunctionType<ComputedValueType>, |
33 | | - config?: CreateComputedConfigInterfaceWithAgile |
34 | | -): Computed<ComputedValueType>; |
35 | | -/** |
36 | | - * Returns a newly created Computed. |
37 | | - * |
38 | | - * A Computed is an extension of the State Class |
39 | | - * that computes its value based on a specified compute function. |
40 | | - * |
41 | | - * The computed value will be cached to avoid unnecessary recomputes |
42 | | - * and is only recomputed when one of its direct dependencies changes. |
43 | | - * |
44 | | - * Direct dependencies can be States and Collections. |
45 | | - * So when, for example, a dependent State value changes, the computed value is recomputed. |
46 | | - * |
47 | | - * [Learn more..](https://agile-ts.org/docs/core/agile-instance/methods#createcomputed) |
48 | | - * |
49 | | - * @public |
50 | | - * @param computeFunction - Function to compute the computed value. |
51 | | - * @param deps - Hard-coded dependencies on which the Computed Class should depend. |
52 | | - */ |
53 | | -export function createComputed<ComputedValueType = any>( |
54 | | - computeFunction: ComputeFunctionType<ComputedValueType>, |
55 | | - deps?: Array<DependableAgileInstancesType> |
56 | | -): Computed<ComputedValueType>; |
57 | | -export function createComputed<ComputedValueType = any>( |
58 | | - computeFunction: ComputeFunctionType<ComputedValueType>, |
59 | | - configOrDeps?: |
60 | | - | CreateComputedConfigInterfaceWithAgile |
61 | | - | Array<DependableAgileInstancesType> |
62 | | -): Computed<ComputedValueType> { |
63 | | - let _config: CreateComputedConfigInterfaceWithAgile = {}; |
64 | | - |
65 | | - if (Array.isArray(configOrDeps)) { |
66 | | - _config = defineConfig(_config, { |
67 | | - computedDeps: configOrDeps, |
68 | | - }); |
69 | | - } else { |
70 | | - if (configOrDeps) _config = configOrDeps; |
71 | | - } |
72 | | - |
73 | | - _config = defineConfig(_config, { agileInstance: shared }); |
74 | | - |
75 | | - return new Computed<ComputedValueType>( |
76 | | - _config.agileInstance as any, |
77 | | - computeFunction, |
78 | | - _config |
79 | | - ); |
80 | | -} |
81 | | - |
82 | | -export interface CreateComputedConfigInterfaceWithAgile |
83 | | - extends CreateAgileSubInstanceInterface, |
84 | | - CreateComputedConfigInterface {} |
| 4 | +// Outsourced from here because of tree shaking issues (See: https://github.com/agile-ts/agile/issues/196) |
| 5 | +export * from './public'; |
0 commit comments