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

Commit beac84d

Browse files
authored
Merge pull request #197 from agile-ts/enhancedState-treeShaking-issue
separated createState and createLightState to prevent tree-shaking issue
2 parents 47922ee + ef10f0c commit beac84d

File tree

6 files changed

+115
-71
lines changed

6 files changed

+115
-71
lines changed

packages/core/src/state/index.ts

Lines changed: 2 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -1,77 +1,8 @@
1-
import { defineConfig, removeProperties } from '@agile-ts/utils';
2-
import { CreateAgileSubInstanceInterface, shared } from '../shared';
3-
import { State, StateConfigInterface } from './state';
4-
import { EnhancedState } from './state.enhanced';
5-
61
export * from './state';
72
export * from './state.observer';
83
export * from './state.enhanced';
94
export * from './state.persistent';
105
export * from './state.runtime.job';
116

12-
/**
13-
* Returns a newly created State.
14-
*
15-
* A State manages a piece of Information
16-
* that we need to remember globally at a later point in time.
17-
* While providing a toolkit to use and mutate this piece of Information.
18-
*
19-
* You can create as many global States as you need.
20-
*
21-
* [Learn more..](https://agile-ts.org/docs/core/agile-instance/methods#createstate)
22-
*
23-
* @public
24-
* @param initialValue - Initial value of the State.
25-
* @param config - Configuration object
26-
*/
27-
export function createLightState<ValueType = any>(
28-
initialValue: ValueType,
29-
config: CreateStateConfigInterfaceWithAgile = {}
30-
): State<ValueType> {
31-
config = defineConfig(config, {
32-
agileInstance: shared,
33-
});
34-
return new State<ValueType>(
35-
config.agileInstance as any,
36-
initialValue,
37-
removeProperties(config, ['agileInstance'])
38-
);
39-
}
40-
41-
// TODO 'createState' doesn't get entirely treeshaken away (React project)
42-
/**
43-
* Returns a newly created enhanced State.
44-
*
45-
* An enhanced State manages, like a normal State, a piece of Information
46-
* that we need to remember globally at a later point in time.
47-
* While providing a toolkit to use and mutate this piece of Information.
48-
*
49-
* The main difference to a normal State is however
50-
* that an enhanced State provides a wider variety of inbuilt utilities (like a persist, undo, watch functionality)
51-
* but requires a larger bundle size in return.
52-
*
53-
* You can create as many global enhanced States as you need.
54-
*
55-
* [Learn more..](https://agile-ts.org/docs/core/agile-instance/methods#createstate)
56-
*
57-
* @public
58-
* @param initialValue - Initial value of the State.
59-
* @param config - Configuration object
60-
*/
61-
export function createState<ValueType = any>(
62-
initialValue: ValueType,
63-
config: CreateStateConfigInterfaceWithAgile = {}
64-
): EnhancedState<ValueType> {
65-
config = defineConfig(config, {
66-
agileInstance: shared,
67-
});
68-
return new EnhancedState<ValueType>(
69-
config.agileInstance as any,
70-
initialValue,
71-
removeProperties(config, ['agileInstance'])
72-
);
73-
}
74-
75-
export interface CreateStateConfigInterfaceWithAgile
76-
extends CreateAgileSubInstanceInterface,
77-
StateConfigInterface {}
7+
// Outsourced from here because of tree shaking issues (See: https://github.com/agile-ts/agile/issues/196)
8+
export * from './public';
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import { defineConfig, removeProperties } from '@agile-ts/utils';
2+
import { shared } from '../../shared';
3+
import { EnhancedState } from '../state.enhanced';
4+
import { CreateStateConfigInterfaceWithAgile } from './index';
5+
6+
/**
7+
* Returns a newly created enhanced State.
8+
*
9+
* An enhanced State manages, like a normal State, a piece of Information
10+
* that we need to remember globally at a later point in time.
11+
* While providing a toolkit to use and mutate this piece of Information.
12+
*
13+
* The main difference to a normal State is however
14+
* that an enhanced State provides a wider variety of inbuilt utilities (like a persist, undo, watch functionality)
15+
* but requires a larger bundle size in return.
16+
*
17+
* You can create as many global enhanced States as you need.
18+
*
19+
* [Learn more..](https://agile-ts.org/docs/core/agile-instance/methods#createstate)
20+
*
21+
* @public
22+
* @param initialValue - Initial value of the State.
23+
* @param config - Configuration object
24+
*/
25+
export function createEnhancedState<ValueType = any>(
26+
initialValue: ValueType,
27+
config: CreateStateConfigInterfaceWithAgile = {}
28+
): EnhancedState<ValueType> {
29+
config = defineConfig(config, {
30+
agileInstance: shared,
31+
});
32+
return new EnhancedState<ValueType>(
33+
config.agileInstance as any,
34+
initialValue,
35+
removeProperties(config, ['agileInstance'])
36+
);
37+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import { defineConfig, removeProperties } from '@agile-ts/utils';
2+
import { shared } from '../../shared';
3+
import { State } from '../state';
4+
import { CreateStateConfigInterfaceWithAgile } from './index';
5+
6+
/**
7+
* Returns a newly created State.
8+
*
9+
* A State manages a piece of Information
10+
* that we need to remember globally at a later point in time.
11+
* While providing a toolkit to use and mutate this piece of Information.
12+
*
13+
* You can create as many global States as you need.
14+
*
15+
* [Learn more..](https://agile-ts.org/docs/core/agile-instance/methods#createstate)
16+
*
17+
* @public
18+
* @param initialValue - Initial value of the State.
19+
* @param config - Configuration object
20+
*/
21+
export function createLightState<ValueType = any>(
22+
initialValue: ValueType,
23+
config: CreateStateConfigInterfaceWithAgile = {}
24+
): State<ValueType> {
25+
config = defineConfig(config, {
26+
agileInstance: shared,
27+
});
28+
return new State<ValueType>(
29+
config.agileInstance as any,
30+
initialValue,
31+
removeProperties(config, ['agileInstance'])
32+
);
33+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import {
2+
createEnhancedState,
3+
CreateStateConfigInterfaceWithAgile,
4+
} from './index';
5+
import { EnhancedState } from '../state.enhanced';
6+
7+
/**
8+
* Returns a newly created enhanced State.
9+
*
10+
* An enhanced State manages, like a normal State, a piece of Information
11+
* that we need to remember globally at a later point in time.
12+
* While providing a toolkit to use and mutate this piece of Information.
13+
*
14+
* The main difference to a normal State is however
15+
* that an enhanced State provides a wider variety of inbuilt utilities (like a persist, undo, watch functionality)
16+
* but requires a larger bundle size in return.
17+
*
18+
* You can create as many global enhanced States as you need.
19+
*
20+
* [Learn more..](https://agile-ts.org/docs/core/agile-instance/methods#createstate)
21+
*
22+
* @public
23+
* @param initialValue - Initial value of the State.
24+
* @param config - Configuration object
25+
*/
26+
export function createState<ValueType = any>(
27+
initialValue: ValueType,
28+
config: CreateStateConfigInterfaceWithAgile = {}
29+
): EnhancedState<ValueType> {
30+
return createEnhancedState(initialValue, config);
31+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import { CreateAgileSubInstanceInterface } from '../../shared';
2+
import { StateConfigInterface } from '../state';
3+
4+
export * from './createState';
5+
export * from './createEnhancedState';
6+
export * from './createLightState';
7+
8+
export interface CreateStateConfigInterfaceWithAgile
9+
extends CreateAgileSubInstanceInterface,
10+
StateConfigInterface {}

packages/event/src/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
import { Event } from './event';
22

33
export * from './event';
4+
export * from './react';
5+
46
export default Event;

0 commit comments

Comments
 (0)