import { OrderedMap, Map, List, RecordOf } from 'immutable' import { SchemaTypesType } from '@ui-schema/ui-schema/CommonTypings' import { UIStoreActions, UIStoreUpdaterData } from '@ui-schema/ui-schema/UIStoreActions' export type Values = List | string | number | boolean | Map | OrderedMap export type ValuesJS = any[] | string | number | boolean | Object export interface UIStoreStateData { values: D internals: UIStoreInternalsType validity: UIStoreValidityType meta: Map } export interface UIStoreState extends UIStoreStateData { // returns the values in `values` as pure JS, even when saved as `Map` or `List` valuesToJS: () => ValuesJS // todo: correct typing `getValues` return value getValues: () => D getInternals: () => UIStoreInternalsType getValidity: () => UIStoreValidityType extractValues: (storeKeys: StoreKeys) => { value: V | undefined internalValue: UIStoreInternalsType | undefined } } export type UIStoreType = RecordOf> /** * the `internals` are nested for safer generic usage, only the key `internals` is reserved (for nesting) * {} = {internals: Map({})} * {prop_a: 20} = {internals: Map({ * prop_a: Map({internals: Map({})}) * })} */ export type UIStoreInternalsType = Map export type UIStoreValidityType = Map export const UIStore: UIStoreType export type UIStoreUpdaterFn = (data: D) => D export type onChangeHandler = (actions: A[] | A) => void // UIMetaContext // Hooks & HOCs export function createStore(data: D): UIStoreType export function createEmptyStore(type?: SchemaTypesType): UIStoreType<[] | '' | 0 | false | {}> // UIStore / Immutable Manipulation Functions export type StoreKeyType = string | number /** * @deprecated use `StoreKeyType` instead */ export type OwnKey = StoreKeyType export type StoreKeys = List export function prependKey>(storeKeys: S, key: O): S export function shouldDeleteOnEmpty(value: any, force?: boolean, type?: SchemaTypesType): boolean export function addNestKey(storeKeysNestedKey: string, storeKeys: StoreKeys): StoreKeys