Skip to content
This repository was archived by the owner on Oct 16, 2024. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
73 changes: 2 additions & 71 deletions packages/core/src/state/index.ts
Original file line number Diff line number Diff line change
@@ -1,77 +1,8 @@
import { defineConfig, removeProperties } from '@agile-ts/utils';
import { CreateAgileSubInstanceInterface, shared } from '../shared';
import { State, StateConfigInterface } from './state';
import { EnhancedState } from './state.enhanced';

export * from './state';
export * from './state.observer';
export * from './state.enhanced';
export * from './state.persistent';
export * from './state.runtime.job';

/**
* Returns a newly created State.
*
* A State manages a piece of Information
* that we need to remember globally at a later point in time.
* While providing a toolkit to use and mutate this piece of Information.
*
* You can create as many global States as you need.
*
* [Learn more..](https://agile-ts.org/docs/core/agile-instance/methods#createstate)
*
* @public
* @param initialValue - Initial value of the State.
* @param config - Configuration object
*/
export function createLightState<ValueType = any>(
initialValue: ValueType,
config: CreateStateConfigInterfaceWithAgile = {}
): State<ValueType> {
config = defineConfig(config, {
agileInstance: shared,
});
return new State<ValueType>(
config.agileInstance as any,
initialValue,
removeProperties(config, ['agileInstance'])
);
}

// TODO 'createState' doesn't get entirely treeshaken away (React project)
/**
* Returns a newly created enhanced State.
*
* An enhanced State manages, like a normal State, a piece of Information
* that we need to remember globally at a later point in time.
* While providing a toolkit to use and mutate this piece of Information.
*
* The main difference to a normal State is however
* that an enhanced State provides a wider variety of inbuilt utilities (like a persist, undo, watch functionality)
* but requires a larger bundle size in return.
*
* You can create as many global enhanced States as you need.
*
* [Learn more..](https://agile-ts.org/docs/core/agile-instance/methods#createstate)
*
* @public
* @param initialValue - Initial value of the State.
* @param config - Configuration object
*/
export function createState<ValueType = any>(
initialValue: ValueType,
config: CreateStateConfigInterfaceWithAgile = {}
): EnhancedState<ValueType> {
config = defineConfig(config, {
agileInstance: shared,
});
return new EnhancedState<ValueType>(
config.agileInstance as any,
initialValue,
removeProperties(config, ['agileInstance'])
);
}

export interface CreateStateConfigInterfaceWithAgile
extends CreateAgileSubInstanceInterface,
StateConfigInterface {}
// Outsourced from here because of tree shaking issues (See: https://github.com/agile-ts/agile/issues/196)
export * from './public';
37 changes: 37 additions & 0 deletions packages/core/src/state/public/createEnhancedState.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import { defineConfig, removeProperties } from '@agile-ts/utils';
import { shared } from '../../shared';
import { EnhancedState } from '../state.enhanced';
import { CreateStateConfigInterfaceWithAgile } from './index';

/**
* Returns a newly created enhanced State.
*
* An enhanced State manages, like a normal State, a piece of Information
* that we need to remember globally at a later point in time.
* While providing a toolkit to use and mutate this piece of Information.
*
* The main difference to a normal State is however
* that an enhanced State provides a wider variety of inbuilt utilities (like a persist, undo, watch functionality)
* but requires a larger bundle size in return.
*
* You can create as many global enhanced States as you need.
*
* [Learn more..](https://agile-ts.org/docs/core/agile-instance/methods#createstate)
*
* @public
* @param initialValue - Initial value of the State.
* @param config - Configuration object
*/
export function createEnhancedState<ValueType = any>(
initialValue: ValueType,
config: CreateStateConfigInterfaceWithAgile = {}
): EnhancedState<ValueType> {
config = defineConfig(config, {
agileInstance: shared,
});
return new EnhancedState<ValueType>(
config.agileInstance as any,
initialValue,
removeProperties(config, ['agileInstance'])
);
}
33 changes: 33 additions & 0 deletions packages/core/src/state/public/createLightState.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import { defineConfig, removeProperties } from '@agile-ts/utils';
import { shared } from '../../shared';
import { State } from '../state';
import { CreateStateConfigInterfaceWithAgile } from './index';

/**
* Returns a newly created State.
*
* A State manages a piece of Information
* that we need to remember globally at a later point in time.
* While providing a toolkit to use and mutate this piece of Information.
*
* You can create as many global States as you need.
*
* [Learn more..](https://agile-ts.org/docs/core/agile-instance/methods#createstate)
*
* @public
* @param initialValue - Initial value of the State.
* @param config - Configuration object
*/
export function createLightState<ValueType = any>(
initialValue: ValueType,
config: CreateStateConfigInterfaceWithAgile = {}
): State<ValueType> {
config = defineConfig(config, {
agileInstance: shared,
});
return new State<ValueType>(
config.agileInstance as any,
initialValue,
removeProperties(config, ['agileInstance'])
);
}
31 changes: 31 additions & 0 deletions packages/core/src/state/public/createState.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import {
createEnhancedState,
CreateStateConfigInterfaceWithAgile,
} from './index';
import { EnhancedState } from '../state.enhanced';

/**
* Returns a newly created enhanced State.
*
* An enhanced State manages, like a normal State, a piece of Information
* that we need to remember globally at a later point in time.
* While providing a toolkit to use and mutate this piece of Information.
*
* The main difference to a normal State is however
* that an enhanced State provides a wider variety of inbuilt utilities (like a persist, undo, watch functionality)
* but requires a larger bundle size in return.
*
* You can create as many global enhanced States as you need.
*
* [Learn more..](https://agile-ts.org/docs/core/agile-instance/methods#createstate)
*
* @public
* @param initialValue - Initial value of the State.
* @param config - Configuration object
*/
export function createState<ValueType = any>(
initialValue: ValueType,
config: CreateStateConfigInterfaceWithAgile = {}
): EnhancedState<ValueType> {
return createEnhancedState(initialValue, config);
}
10 changes: 10 additions & 0 deletions packages/core/src/state/public/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { CreateAgileSubInstanceInterface } from '../../shared';
import { StateConfigInterface } from '../state';

export * from './createState';
export * from './createEnhancedState';
export * from './createLightState';

export interface CreateStateConfigInterfaceWithAgile
extends CreateAgileSubInstanceInterface,
StateConfigInterface {}
2 changes: 2 additions & 0 deletions packages/event/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import { Event } from './event';

export * from './event';
export * from './react';

export default Event;