import type { MMap } from "./MMap"; import { GenericComplexEntity, GenericEntity, GenericGroupEntity, Context } from "./Entities"; /** * Entity Base Class. It has event handlers for attaching, detaching and updating props. Has a method for providing and using context. * @typeParam Props - Type of input props of the Entity. * @typeParam DefaultProps - Type of default input props of the Entity. * @example * ```ts * type MMapSomeEntityProps = { * name?: string; * }; * const defaultProps = { * name: 'entity' * }; * class MMapSomeEntity extends MMapEntity { * static defaultProps = defaultProps; * public isAttached: boolean; * constructor(props: MMapSomeEntityProps) { * super(props); * this.isAttached = false * // Additional actions can be taken in the constructor of a class. * } * protected _onAttach(): void { * this.isAttached = true; * // Additional actions can be taken when an Entity is attached. * } * // ... * } * ``` */ declare abstract class MMapEntity extends GenericEntity { get root(): null | MMap; get parent(): null | MMapComplexEntity; } /** * Entity that aggregates multiple Entities but looks basic from the outside. * @typeParam Props - Type of input props of the Entity. * @typeParam DefaultProps - Type of default input props of the Entity. * @typeParam Root - Root Entity Class. * @example * ```ts * type MMapSomeComplexEntityProps = { * name?: string; * }; * const defaultProps = { * name: 'entity' * }; * class MMapSomeComplexEntity extends MMapComplexEntity { * static defaultProps = defaultProps; * private _someEntity?: MMapSomeEntity; // MMapSomeEntity extends GenericEntity * protected _onAttach(): void { * this._someEntity = new MMapSomeEntity(); * this.addChild(this._someEntity); // add someEntity as children * // ... * } * // ... * } * ``` */ declare abstract class MMapComplexEntity extends GenericComplexEntity implements MMapEntity { get root(): null | MMap; get parent(): null | MMapComplexEntity; } /** * Entity that aggregates multiple Entities, and allows you to publicly add and remove entities to a subtree. * @typeParam Props - Type of input props of the Entity. * @typeParam DefaultProps - Type of default input props of the Entity. * @typeParam Root - Root Entity Class. * @example * ```ts * type MMapSomeGroupEntityProps = { * name?: string; * }; * const defaultProps = { * name: 'entity' * }; * class MMapSomeGroupEntity extends MMapGroupEntity { * static defaultProps = defaultProps; * // ... * } * const groupEntity = new MMapSomeGroupEntity() * const someEntity = new MMapSomeEntity(); // MMapSomeEntity extends GenericEntity * groupEntity.addChild(someEntity); // add someEntity in MMapSomeGroupEntity object * groupEntity.removeChild(someEntity); // remove someEntity from MMapSomeGroupEntity object * ``` */ declare abstract class MMapGroupEntity extends GenericGroupEntity implements MMapComplexEntity { get root(): null | MMap; get parent(): null | MMapComplexEntity; readonly children: readonly MMapEntity[]; addChild(child: MMapEntity, index?: number): this; removeChild(child: MMapEntity): this; } /** * Context for MMap. It allows you to provide a value to the context and use it in the children of the context provider. * ```ts * const MMapSomeContext = new mappable.MMapContext('MMapSomeContext'); * class SomeValueProvider extends mappable.MMapGroupEntity<{}> { * constructor() { * super({}); * this._provideContext(MMapSomeContext, {your: 'value'}); // Special method to provide context value * } * } * ``` * And some child entity can use this context: * ```ts * class SomeContextConsumer extends mappable.MMapEntity<{}> { * constructor() { * super({}); * } * * _onAttach() { * const value = this._consumeContext(MMapSomeContext); // Special method to get context value * console.log(value); // {your: 'value'} * } * } * ``` * In any level of nesting: * ```tsx * * * * * * * * ``` * You can set the context value using [[MMapContextProvider]]: * ```tsx * * * * * * * * ``` */ declare class MMapContext extends Context { } export { MMapEntity, MMapComplexEntity, MMapGroupEntity, MMapContext };