diff --git a/packages/core/src/state/index.ts b/packages/core/src/state/index.ts index 4caa8d5a..3195df90 100644 --- a/packages/core/src/state/index.ts +++ b/packages/core/src/state/index.ts @@ -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( - initialValue: ValueType, - config: CreateStateConfigInterfaceWithAgile = {} -): State { - config = defineConfig(config, { - agileInstance: shared, - }); - return new State( - 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( - initialValue: ValueType, - config: CreateStateConfigInterfaceWithAgile = {} -): EnhancedState { - config = defineConfig(config, { - agileInstance: shared, - }); - return new EnhancedState( - 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'; diff --git a/packages/core/src/state/public/createEnhancedState.ts b/packages/core/src/state/public/createEnhancedState.ts new file mode 100644 index 00000000..6e64a675 --- /dev/null +++ b/packages/core/src/state/public/createEnhancedState.ts @@ -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( + initialValue: ValueType, + config: CreateStateConfigInterfaceWithAgile = {} +): EnhancedState { + config = defineConfig(config, { + agileInstance: shared, + }); + return new EnhancedState( + config.agileInstance as any, + initialValue, + removeProperties(config, ['agileInstance']) + ); +} diff --git a/packages/core/src/state/public/createLightState.ts b/packages/core/src/state/public/createLightState.ts new file mode 100644 index 00000000..4055f734 --- /dev/null +++ b/packages/core/src/state/public/createLightState.ts @@ -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( + initialValue: ValueType, + config: CreateStateConfigInterfaceWithAgile = {} +): State { + config = defineConfig(config, { + agileInstance: shared, + }); + return new State( + config.agileInstance as any, + initialValue, + removeProperties(config, ['agileInstance']) + ); +} diff --git a/packages/core/src/state/public/createState.ts b/packages/core/src/state/public/createState.ts new file mode 100644 index 00000000..3a75772a --- /dev/null +++ b/packages/core/src/state/public/createState.ts @@ -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( + initialValue: ValueType, + config: CreateStateConfigInterfaceWithAgile = {} +): EnhancedState { + return createEnhancedState(initialValue, config); +} diff --git a/packages/core/src/state/public/index.ts b/packages/core/src/state/public/index.ts new file mode 100644 index 00000000..42ac2aed --- /dev/null +++ b/packages/core/src/state/public/index.ts @@ -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 {} diff --git a/packages/event/src/index.ts b/packages/event/src/index.ts index a5206c74..09aba335 100644 --- a/packages/event/src/index.ts +++ b/packages/event/src/index.ts @@ -1,4 +1,6 @@ import { Event } from './event'; export * from './event'; +export * from './react'; + export default Event;