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

Commit ef10f0c

Browse files
committed
renamed createState
1 parent 633c308 commit ef10f0c

File tree

3 files changed

+43
-11
lines changed

3 files changed

+43
-11
lines changed
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+
}

packages/core/src/state/public/createState.ts

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
import { defineConfig, removeProperties } from '@agile-ts/utils';
2-
import { shared } from '../../shared';
1+
import {
2+
createEnhancedState,
3+
CreateStateConfigInterfaceWithAgile,
4+
} from './index';
35
import { EnhancedState } from '../state.enhanced';
4-
import { CreateStateConfigInterfaceWithAgile } from './index';
56

67
/**
78
* Returns a newly created enhanced State.
@@ -26,12 +27,5 @@ export function createState<ValueType = any>(
2627
initialValue: ValueType,
2728
config: CreateStateConfigInterfaceWithAgile = {}
2829
): 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-
);
30+
return createEnhancedState(initialValue, config);
3731
}

packages/core/src/state/public/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { CreateAgileSubInstanceInterface } from '../../shared';
22
import { StateConfigInterface } from '../state';
33

44
export * from './createState';
5+
export * from './createEnhancedState';
56
export * from './createLightState';
67

78
export interface CreateStateConfigInterfaceWithAgile

0 commit comments

Comments
 (0)