{"version":3,"file":"core.cjs","sources":["../../package/core/Dispatcher.ts","../../package/core/Payload.ts","../../package/core/Neuron.ts","../../package/core/NeuronClient.ts","../../package/core/Module.ts"],"sourcesContent":["import { NeuronKey } from \"./Neuron\";\nimport { IPayload } from \"./Payload\";\n\nexport class Dispatcher<T> implements IDispatcher<T> {\n  private eventEmitters: Map<NeuronKey, Set<DispatchCallback<T>>> = new Map();\n  private payload?: IPayload<T>;\n\n  /**\n   * Registers a callback to listen to changes associated with the given key.\n   * @param key - The unique identifier for the Neuron whose state changes should be listened to.\n   * @param callback - The function to invoke when the state changes.\n   */\n  listen(key: NeuronKey, callback: DispatchCallback<T>) {\n    if (!this.eventEmitters.has(key)) {\n      this.eventEmitters.set(key, new Set());\n    }\n    this.eventEmitters.get(key)?.add(callback);\n\n    // Immediately invoke the callback with the current state, if available\n    if (this.payload?.key === key) {\n      callback(this.payload);\n    }\n  }\n\n  /**\n   * Stops listening for changes for the given key and removes the specific callback.\n   * @param key - The unique identifier for the Neuron.\n   * @param callback - The callback to remove from the listeners.\n   */\n  stopListening(key: NeuronKey, callback: DispatchCallback<T>) {\n    const listeners = this.eventEmitters.get(key);\n    if (listeners) {\n      listeners.delete(callback);\n      if (listeners.size === 0) {\n        this.eventEmitters.delete(key); // Clean up if no listeners remain\n      }\n    }\n  }\n\n  /**\n   * Dispatches a payload to all registered listeners associated with the payload's key.\n   * @param payload - The payload containing the state and metadata to dispatch.\n   */\n  dispatch(payload: IPayload<T>) {\n    this.payload = payload;\n    const listeners = this.eventEmitters.get(payload.key);\n    listeners?.forEach((listener) => {\n      listener(payload);\n    });\n  }\n}\n\n/**\n * Interface for a dispatcher that listens to state changes and dispatches payloads to registered callbacks.\n *\n * @template T - The type of the state being managed.\n */\nexport interface IDispatcher<T> {\n  /**\n   * Registers a callback to be invoked whenever the state associated with the given key changes.\n   *\n   * @param key - The unique identifier for the Neuron whose state changes should be listened to.\n   * @param callbackfn - The function to call when the state changes. It receives the payload with the new state.\n   */\n  listen: (key: NeuronKey, callbackfn: DispatchCallback<T>) => void;\n\n  /**\n   * Unregisters all callbacks associated with the given key, effectively stopping any listening on that key.\n   *\n   * @param key - The unique identifier for the Neuron whose state changes should no longer be listened to.\n   */\n  stopListening: (key: NeuronKey, callback: DispatchCallback<T>) => void;\n\n  /**\n   * Dispatches the given payload to all registered callbacks associated with the payload's key.\n   *\n   * @param payload - The payload containing the state and metadata to be dispatched.\n   */\n  dispatch: (payload: IPayload<T>) => void;\n}\n\n/**\n * Type representing a function that dispatches a mutator function to modify the state.\n *\n * @template T - The type of the state being managed.\n * @template F - The type of additional features or metadata associated with the state.\n */\nexport type Dispatch<T> = (mutator: DispatchMutator<T>) => void;\n\n/**\n * Type representing a mutator function that modifies the payload's state.\n *\n * @template T - The type of the state being managed.\n */\nexport type DispatchMutator<T> = (payload: IPayload<T>) => void;\n\n/**\n * Type representing a callback function that processes a dispatched payload.\n *\n * @template T - The type of the state being managed.\n *\n * @param payload - The payload containing the current state and metadata.\n */\nexport type DispatchCallback<T> = (payload: Readonly<IPayload<T>>) => void;\n","import { NeuronKey } from \"./Neuron\";\n\nexport class Payload<T> implements IPayload<T> {\n  readonly key: NeuronKey;\n  readonly prevState: Readonly<T>;\n  state: T;\n  #dispatchCancelled = false;\n  readonly cancelDispatch = () => {\n    this.#dispatchCancelled = true;\n  };\n  readonly isDispatchCancelled = () => this.#dispatchCancelled;\n  constructor(options: PayloadParams<T>) {\n    this.key = options.key;\n    this.prevState = options.prevState;\n    this.state = options.state;\n  }\n}\n\n/**\n * Interface for a Payload object, which contains the data necessary for updating state\n * and running middleware during state transitions.\n *\n * @template T - The type of the state being managed.\n */\nexport interface IPayload<T = unknown> {\n  /**\n   * The unique key associated with the Neuron state.\n   */\n  readonly key: Readonly<NeuronKey>;\n\n  /**\n   * The current state of the Neuron.\n   */\n  state: T;\n\n  /**\n   * The previous state of the Neuron.\n   */\n  readonly prevState: Readonly<T>;\n\n  /**\n   * Cancels the dispatch operation for the current payload.\n   */\n  readonly cancelDispatch: () => void;\n\n  /**\n   * Checks if the dispatch operation for the current payload has been canceled.\n   *\n   * @returns `true` if the dispatch is canceled; otherwise `false`.\n   */\n  readonly isDispatchCancelled: () => boolean;\n}\n\n/**\n * Parameters for creating a new Payload instance.\n *\n * @template T - The type of the state being managed.\n */\nexport interface PayloadParams<T> {\n  /**\n   * The unique key associated with the Neuron state.\n   */\n  key: NeuronKey;\n\n  /**\n   * The previous state of the Neuron.\n   */\n  prevState: T;\n\n  /**\n   * The current state of the Neuron.\n   */\n  state: T;\n}\n","import {\n  Dispatch,\n  DispatchCallback,\n  Dispatcher,\n  DispatchMutator,\n  IDispatcher,\n} from \"./Dispatcher\";\nimport { IModule } from \"./Module\";\nimport { ClientStore } from \"./NeuronClient\";\nimport { IPayload, Payload } from \"./Payload\";\n\nexport class Neuron<T, A = unknown> implements INeuron<T, A> {\n  private store: ClientStore<unknown, unknown>;\n  private modules: IModule[];\n  private dispatcher: IDispatcher<T>;\n  readonly key: NeuronKey;\n  readonly set = (newState: T | ((prevState: T) => T)) => {\n    const neuronData = this.store.get(this.key) as NeuronData<T, A>;\n    const prevState = neuronData.state;\n    const payload = new Payload<T>({\n      key: this.key,\n      prevState: prevState,\n      state:\n        typeof newState === \"function\"\n          ? (newState as (prevState: T) => T)(neuronData?.state as T)\n          : newState,\n    });\n    if (payload.state !== payload.prevState) {\n      neuronData?.onDispatch?.(payload);\n      for (let i = 0; i < this.modules.length; i++) {\n        if (!payload.isDispatchCancelled()) {\n          this.modules[i].onDispatch?.(payload as IPayload<unknown>);\n          continue;\n        }\n        break;\n      }\n      if (!payload.isDispatchCancelled()) {\n        this.store.set(this.key, {\n          ...neuronData,\n          state: payload?.state,\n          prevState: prevState,\n        } as NeuronData<unknown, A>);\n        this.dispatcher.dispatch(payload);\n        neuronData?.onCallback?.(payload);\n        this.modules.forEach((module) => {\n          module?.onCallback?.(payload as IPayload<unknown>);\n        });\n      }\n    }\n  };\n  readonly getClone = () => {\n    const neuronState = this.store.get(this.key)?.state as T;\n    if (structuredClone !== undefined || structuredClone !== null) {\n      return structuredClone(neuronState);\n    }\n    return neuronState;\n  };\n  readonly getRef = () => this.store.get(this.key)?.state as T;\n  readonly dispatch = (mutator: DispatchMutator<T>) => {\n    const neuronData = this.store.get(this.key) as NeuronData<T, A>;\n    const payload = new Payload<T>({\n      key: this.key,\n      state: neuronData?.state,\n      prevState: neuronData?.state,\n    });\n    mutator(payload);\n    if (!payload.isDispatchCancelled()) {\n      neuronData?.onDispatch?.(payload);\n      for (let i = 0; i < this.modules.length; i++) {\n        if (!payload.isDispatchCancelled()) {\n          this.modules[i].onDispatch?.(payload as IPayload<unknown>);\n          continue;\n        }\n        break;\n      }\n    }\n    if (!payload.isDispatchCancelled()) {\n      const newNeuronData = {\n        ...neuronData,\n        state: payload.state,\n        prevState: neuronData.state,\n      };\n      this.store.set(this.key, newNeuronData as NeuronData<unknown, A>);\n      this.dispatcher.dispatch(payload);\n      neuronData?.onCallback?.(payload);\n      this.modules.forEach((module) => {\n        module?.onCallback?.(payload as IPayload<unknown>);\n      });\n    }\n  };\n  readonly getActions = () => {\n    const neuronActions = (this.store.get(this.key) as NeuronData<T, A>)\n      ?.actions;\n    return (neuronActions?.(this.dispatch) as A) ?? ({} as A);\n  };\n  readonly effect = (callbackFn: DispatchCallback<T>) => {\n    this.dispatcher.stopListening(this.key, callbackFn);\n    this.dispatcher.listen(this.key, callbackFn);\n  };\n\n  constructor(\n    initialState: T,\n    options?: NeuronOptions<T, A>,\n    clientStore?: ClientStore<unknown, unknown>,\n    dispatcher?: IDispatcher<T>\n  ) {\n    this.key = options?.key ?? crypto.randomUUID();\n    this.store =\n      clientStore ?? new Map<NeuronKey, NeuronData<unknown, unknown>>();\n    this.modules = options?.modules ?? [];\n    this.dispatcher = dispatcher ?? new Dispatcher<T>();\n    const payload = new Payload<T>({\n      key: this.key,\n      state: initialState,\n      prevState: initialState,\n    });\n    options?.onInit?.(payload);\n    this.modules.forEach((module) => {\n      module?.onInit?.(payload as IPayload<unknown>);\n    });\n    this.store.set(payload.key, {\n      ...options,\n      key: payload.key,\n      state: payload?.state,\n      prevState: payload?.prevState,\n    } as NeuronData<unknown, A>);\n  }\n}\n\n//Neuron Types and Interfaces\n\n/**\n * Interface representing the core functionality of a Neuron,\n * which holds state and provides methods to manipulate it.\n *\n * @template T - The type of the state held by the Neuron.\n * @template A - The type of actions associated with the Neuron.\n */\nexport interface INeuron<T, A> {\n  /**\n   * A unique key identifying the Neuron instance.\n   */\n  readonly key: NeuronKey;\n\n  /**\n   * Updates the state of the Neuron.\n   *\n   * @param newState - The new state to set, or a function that takes the previous state\n   * and returns the updated state.\n   */\n  readonly set: (newState: T | ((prevState: T) => T)) => void;\n\n  /**\n   * Sends a mutator function to process and update the Neuron's state.\n   *\n   * @param mutator - A function that modifies the payload, allowing complex state updates.\n   */\n  readonly dispatch: Dispatch<T>;\n\n  /**\n   * Returns a deep clone of the current Neuron state.\n   *\n   * @returns A cloned copy of the current state.\n   */\n  readonly getClone: () => T;\n\n  /**\n   * Returns a reference to the current state without cloning.\n   *\n   * @returns A reference to the current state.\n   */\n  readonly getRef: () => T;\n\n  /**\n   * Registers a callback function to be invoked whenever the Neuron's state is updated.\n   *\n   * @param callbackFn - A callback function that receives the payload with state details.\n   */\n  readonly effect: (callbackFn: DispatchCallback<T>) => void;\n\n  /**\n   * Retrieves action methods associated with the Neuron,\n   * which are functions for interacting with the state.\n   *\n   * @returns The action methods associated with the Neuron.\n   */\n  readonly getActions: () => A;\n}\n/**\n * Configuration options for creating a Neuron instance.\n *\n * @template T - The type of the initial state.\n * @template A - The type of the actions associated with the Neuron.\n */\nexport interface NeuronOptions<T, A> {\n  /**\n   * A unique key to identify the Neuron. If not provided, a random key is generated.\n   */\n  key?: NeuronKey;\n\n  /**\n   * Takes an array of Neuron Modules for extending Neuron state with more features.\n   */\n  modules?: IModule[];\n\n  /**\n   * A function that generates action methods for interacting with the Neuron's state.\n   */\n  actions?: NeuronActions<T, A>;\n\n  /**\n   * A middleware function invoked during the Neuron's initialization.\n   *\n   * @param payload - The payload containing state details during initialization.\n   */\n  onInit?: NeuronMiddleware<T>;\n\n  /**\n   * A middleware function invoked when the Neuron's state is updated.\n   *\n   * @param payload - The payload containing state details during dispatch.\n   */\n  onDispatch?: NeuronMiddleware<T>;\n\n  /**\n   * A middleware function invoked after the Neuron's state has been updated.\n   *\n   * @param payload - The payload containing state details after dispatch.\n   */\n  onCallback?: NeuronMiddleware<T>;\n}\n/**\n * Represents the data stored in a Neuron instance, including state and middleware.\n *\n * @template T - The type of the state held by the Neuron.\n * @template A - The type of actions associated with the Neuron.\n */\nexport interface NeuronData<T, A> {\n  /**\n   * The unique key identifying the Neuron.\n   */\n  key: Readonly<NeuronKey>;\n\n  /**\n   * The current state of the Neuron.\n   */\n  state: T;\n\n  /**\n   * The previous state of the Neuron, retained for comparison or rollback.\n   */\n  prevState: Readonly<T>;\n\n  /**\n   * A function that generates action methods for interacting with the Neuron's state.\n   */\n  actions?: NeuronActions<T, A>;\n\n  /**\n   * Middleware invoked during the Neuron's initialization.\n   */\n  onInit?: NeuronMiddleware<T>;\n\n  /**\n   * Middleware invoked when the Neuron's state is updated.\n   */\n  onDispatch?: NeuronMiddleware<T>;\n\n  /**\n   * Middleware invoked after the Neuron's state has been updated.\n   */\n  onCallback?: NeuronMiddleware<T>;\n}\n\n/**\n * A middleware function used during various stages of a Neuron's lifecycle.\n *\n * @template T - The type of the state held by the Neuron.\n *\n * @param payload - The payload containing the state and metadata during the middleware execution.\n */\nexport type NeuronMiddleware<T> = (payload: IPayload<T>) => void;\n/**\n * Represents a unique key used to identify a Neuron instance.\n */\nexport type NeuronKey = string | number;\n/**\n * A function that generates action methods for interacting with the Neuron's state.\n *\n * @template T - The type of the state held by the Neuron.\n * @template A - The type of actions to be generated.\n *\n * @param dispatch - The dispatch function for sending state mutations.\n * @returns A collection of action methods.\n */\nexport type NeuronActions<T, A> = (dispatch: Dispatch<T>) => A;\n","import {\n  DispatchCallback,\n  Dispatcher,\n  DispatchMutator,\n  IDispatcher,\n} from \"./Dispatcher\";\nimport { IModule } from \"./Module\";\nimport {\n  INeuron,\n  Neuron,\n  NeuronData,\n  NeuronKey,\n  NeuronOptions,\n} from \"./Neuron\";\nimport { IPayload, Payload } from \"./Payload\";\n\nexport class NeuronClient implements INeuronClient {\n  private clientStore: ClientStore<unknown, unknown>;\n  private clientModules: IModule[];\n  private clientDispatcher: IDispatcher<unknown>;\n  readonly name: ClientName;\n  readonly has = (key: NeuronKey) => this.clientStore.has(key);\n  readonly remove = (key: NeuronKey) => {\n    const isRemoved = this.clientStore.delete(key);\n    this.clientDispatcher.stopListening(key, () => null);\n    return isRemoved;\n  };\n  readonly getRef = <T>(key: NeuronKey) =>\n    this.clientStore.get(key)?.state as T;\n  readonly getActions = <A>(key: NeuronKey) => {\n    const neuronActions = (this.clientStore.get(key) as NeuronData<unknown, A>)\n      ?.actions;\n    return (\n      (neuronActions?.((mutator) => this.dispatch(key, mutator)) as A) ??\n      ({} as A)\n    );\n  };\n  readonly getSnapshot = () =>\n    Array.from(this.clientStore.entries()).map((item) => ({\n      key: item[1].key,\n      state: item[1].state,\n    }));\n  readonly listen = (callbackFn: DispatchCallback<unknown>) => {\n    this.clientStore.forEach((_, key) => {\n      this.clientDispatcher.stopListening(key, callbackFn);\n    });\n    this.clientStore.forEach((_, key) => {\n      this.clientDispatcher.listen(key, callbackFn);\n    });\n  };\n  readonly dispatch = (key: NeuronKey, mutator: DispatchMutator<unknown>) => {\n    const neuronData = this.clientStore.get(key) as NeuronData<\n      unknown,\n      unknown\n    >;\n    const payload = new Payload<unknown>({\n      key: key,\n      state: neuronData?.state,\n      prevState: neuronData?.state,\n    });\n\n    mutator(payload);\n\n    this.clientModules.forEach((module) => {\n      module?.onDispatch?.(payload as IPayload<unknown>);\n    });\n    neuronData?.onDispatch?.(payload);\n    this.clientStore.set(key, {\n      ...neuronData,\n      state: payload.state,\n      prevState: neuronData.state,\n    } as NeuronData<unknown, unknown>);\n    this.clientDispatcher.dispatch(payload);\n    this.clientModules.forEach((module) => {\n      module?.onCallback?.(payload as IPayload<unknown>);\n    });\n    neuronData?.onCallback?.(payload);\n  };\n  readonly neuron = <T, A = unknown>(\n    initialState: T,\n    options?: NeuronOptions<T, A>\n  ) => {\n    return new Neuron<T, A>(\n      initialState,\n      { modules: this.clientModules, ...options },\n      this.clientStore,\n      this.clientDispatcher as IDispatcher<T>\n    );\n  };\n  readonly client: ClientMethods;\n  constructor(options?: ClientOptions) {\n    this.name = options?.name ?? crypto.randomUUID();\n    this.clientStore = new Map<NeuronKey, NeuronData<unknown, unknown>>();\n    this.clientDispatcher = new Dispatcher();\n    this.clientModules = options?.modules ?? [];\n    this.client = {\n      name: this.name,\n      has: this.has,\n      remove: this.remove,\n      getRef: this.getRef,\n      getActions: this.getActions,\n      getSnapshot: this.getSnapshot,\n      listen: this.listen,\n      dispatch: this.dispatch,\n      neuron: this.neuron,\n    };\n  }\n}\n\n/**\n * Interface for a NeuronClient, a container for managing multiple Neurons and their states.\n */\nexport interface INeuronClient {\n  /**\n   * The name of the NeuronClient instance.\n   */\n  readonly name: Readonly<ClientName>;\n\n  /**\n   * Checks if a specific state exists in the client store.\n   *\n   * @param key - The unique key associated with the state item.\n   * @returns `true` if the state exists, otherwise `false`.\n   */\n  readonly has: (key: NeuronKey) => boolean;\n\n  /**\n   * Removes a neuron from the client store by its key.\n   *\n   * @param {NeuronKey} key - The key of the neuron to be removed.\n   * @returns {boolean} - Returns `true` if the neuron was successfully deleted, otherwise `false`.\n   *\n   * @example\n   * const success = client.remove('exampleKey');\n   * console.log(success); // true or false\n   */\n  readonly remove: (key: NeuronKey) => boolean;\n\n  /**\n   * Returns a reference to the state value associated with the provided key.\n   *\n   * @template T - The type of the state value.\n   * @param key - The unique key associated with the state item.\n   * @returns The state value as a reference.\n   */\n  readonly getRef: <T>(key: NeuronKey) => T;\n\n  /**\n   * Retrieves the actions associated with a specific neuron key.\n   *\n   * @template A - The type of the actions object.\n   * @param {NeuronKey} key - The unique key identifying the neuron.\n   * @returns {A} The actions object of the specified type `A` associated with the neuron key.\n   *\n   * @example\n   * const actions = getActions<ActionsInterface>(key);\n   * actions.someAction(); // Invoke an action.\n   */\n  readonly getActions: <A>(key: NeuronKey) => A;\n\n  /**\n   * Returns a snapshot of all state items in the client store.\n   *\n   * @returns An array of objects containing the key and state for each item.\n   */\n  readonly getSnapshot: () => {\n    key: NeuronKey;\n    state: unknown;\n  }[];\n\n  /**\n   * Registers a callback function that will be executed whenever a Neuron's state is updated.\n   *\n   * @param callbackFn - The callback function to invoke on state updates. Receives the payload for inspection.\n   */\n  readonly listen: (callbackFn: DispatchCallback<unknown>) => void;\n\n  /**\n   * Dispatches a mutator function for updating the state associated with a specific key.\n   *\n   * @param key - The unique key associated with the state item to update.\n   * @param mutator - A function that manipulates the state through a payload.\n   */\n  readonly dispatch: (\n    key: NeuronKey,\n    mutator: DispatchMutator<unknown>\n  ) => void;\n\n  /**\n   * Creates a new Neuron instance within the client.\n   *\n   * @template T - The type of the Neuron's state.\n   * @template A - The type of the Neuron's actions.\n   * @param initialState - The initial state of the Neuron.\n   * @param options - Configuration options for the Neuron.\n   * @returns A new instance of the Neuron.\n   */\n  readonly neuron: NeuronInstance;\n\n  /**\n   * Provides access to the NeuronClient without the `connect` method.\n   */\n  readonly client: ClientMethods;\n}\n\n/**\n * Configuration options for a NeuronClient instance.\n */\nexport interface ClientOptions {\n  /**\n   * The name of the NeuronClient instance.\n   */\n  name?: NeuronKey;\n\n  /**\n   * An array of modules to associate with the NeuronClient.\n   */\n  modules?: IModule[];\n}\n\n/**\n * The name type for a NeuronClient, which can be a string or number.\n */\nexport type ClientName = string | number;\n\n/**\n * This object has all Core methods for managing state.\n *\n * @template F - The type of additional features or metadata associated with the client.\n */\nexport type ClientMethods = Omit<INeuronClient, \"client\">;\n\n/**\n * Represents the client store as a map of keys to NeuronData objects.\n *\n * @template T - The type of the Neuron's state.\n * @template A - The type of the Neuron's actions.\n */\nexport type ClientStore<T, A> = Map<NeuronKey, NeuronData<T, A>>;\nexport type NeuronInstance = <T, A>(\n  initialState: T,\n  options?: NeuronOptions<T, A>\n) => INeuron<T, A>;\n","import { NeuronMiddleware } from \"./Neuron\";\n\nexport class Module implements IModule {\n  readonly name: string;\n  readonly onInit?: NeuronMiddleware<unknown>;\n  readonly onDispatch?: NeuronMiddleware<unknown>;\n  readonly onCallback?: NeuronMiddleware<unknown>;\n  constructor(options: ModuleOptions) {\n    this.name = options.name;\n    this.onInit = options.onInit;\n    this.onDispatch = options.onDispatch;\n    this.onCallback = options.onCallback;\n  }\n}\n\n/**\n * Interface representing a module that provides lifecycle methods for interacting with Neuron state.\n */\nexport interface IModule {\n  /**\n   * The name of the module.\n   */\n  readonly name: Readonly<string>;\n\n  /**\n   * Optional lifecycle method invoked during the initialization of a Neuron.\n   *\n   * @param payload - The payload containing state and metadata during initialization.\n   */\n  onInit?: NeuronMiddleware<unknown>;\n\n  /**\n   * Optional lifecycle method invoked during the dispatch of a Neuron state change.\n   *\n   * @param payload - The payload containing the updated state and metadata.\n   */\n  onDispatch?: NeuronMiddleware<unknown>;\n\n  /**\n   * Optional lifecycle method invoked after a Neuron state change has been completed.\n   *\n   * @param payload - The payload containing the final state and metadata.\n   */\n  onCallback?: NeuronMiddleware<unknown>;\n}\n\n/**\n * Options for configuring a `Module` instance.\n */\nexport interface ModuleOptions {\n  /**\n   * The name of the module.\n   */\n  name: string;\n\n  /**\n   * Optional lifecycle method invoked during the initialization of a Neuron.\n   *\n   * @param payload - The payload containing state and metadata during initialization.\n   */\n  onInit?: NeuronMiddleware<unknown>;\n\n  /**\n   * Optional lifecycle method invoked during the dispatch of a Neuron state change.\n   *\n   * @param payload - The payload containing the updated state and metadata.\n   */\n  onDispatch?: NeuronMiddleware<unknown>;\n\n  /**\n   * Optional lifecycle method invoked after a Neuron state change has been completed.\n   *\n   * @param payload - The payload containing the final state and metadata.\n   */\n  onCallback?: NeuronMiddleware<unknown>;\n}\n"],"names":["Dispatcher","__publicField","key","callback","_a","_b","listeners","payload","listener","Payload","options","__privateAdd","_dispatchCancelled","__privateSet","__privateGet","Neuron","initialState","clientStore","dispatcher","newState","neuronData","prevState","i","_c","_d","module","neuronState","mutator","newNeuronData","neuronActions","callbackFn","NeuronClient","isRemoved","item","_","Module"],"mappings":"ukBAGO,MAAMA,CAAwC,CAA9C,cACGC,EAAA,yBAA8D,KAC9DA,EAAA,gBAOR,OAAOC,EAAgBC,EAA+B,SAC/C,KAAK,cAAc,IAAID,CAAG,GAC7B,KAAK,cAAc,IAAIA,EAAK,IAAI,GAAK,GAEvCE,EAAA,KAAK,cAAc,IAAIF,CAAG,IAA1B,MAAAE,EAA6B,IAAID,KAG7BE,EAAA,KAAK,UAAL,YAAAA,EAAc,OAAQH,GACxBC,EAAS,KAAK,OAAO,CAEzB,CAOA,cAAcD,EAAgBC,EAA+B,CAC3D,MAAMG,EAAY,KAAK,cAAc,IAAIJ,CAAG,EACxCI,IACFA,EAAU,OAAOH,CAAQ,EACrBG,EAAU,OAAS,GAChB,KAAA,cAAc,OAAOJ,CAAG,EAGnC,CAMA,SAASK,EAAsB,CAC7B,KAAK,QAAUA,EACf,MAAMD,EAAY,KAAK,cAAc,IAAIC,EAAQ,GAAG,EACzCD,GAAA,MAAAA,EAAA,QAASE,GAAa,CAC/BA,EAASD,CAAO,CAAA,EAEpB,CACF,OChDO,MAAME,CAAkC,CAS7C,YAAYC,EAA2B,CAR9BT,EAAA,YACAA,EAAA,kBACTA,EAAA,cACAU,EAAA,KAAAC,EAAqB,IACZX,EAAA,sBAAiB,IAAM,CAC9BY,EAAA,KAAKD,EAAqB,GAAA,GAEnBX,EAAA,2BAAsB,IAAMa,EAAA,KAAKF,IAExC,KAAK,IAAMF,EAAQ,IACnB,KAAK,UAAYA,EAAQ,UACzB,KAAK,MAAQA,EAAQ,KACvB,CACF,CAVEE,EAAA,YCKK,MAAMG,CAAgD,CAyF3D,YACEC,EACAN,EACAO,EACAC,EACA,CA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