diff --git a/packages/core/package.json b/packages/core/package.json index c741fc6f..20d99bfd 100644 --- a/packages/core/package.json +++ b/packages/core/package.json @@ -1,6 +1,6 @@ { "name": "@dark-engine/core", - "version": "0.11.2", + "version": "0.12.0", "description": "Dark is lightweight (10 Kb gzipped) component-and-hook-based UI rendering engine for javascript apps without dependencies and written in TypeScript 💫", "author": "AlexPlex", "license": "MIT", diff --git a/packages/core/types/context/context.d.ts b/packages/core/types/context/context.d.ts index 0e69e26d..415f23c3 100644 --- a/packages/core/types/context/context.d.ts +++ b/packages/core/types/context/context.d.ts @@ -1,3 +1,6 @@ import type { Context } from './types'; -declare function createContext(defaultValue: T): Context; +declare type CreateContextOptions = { + displayName?: string; +}; +declare function createContext(defaultValue: T, options?: CreateContextOptions): Context; export { createContext }; diff --git a/packages/core/types/context/types.d.ts b/packages/core/types/context/types.d.ts index 1bd83a8f..e6b44ff9 100644 --- a/packages/core/types/context/types.d.ts +++ b/packages/core/types/context/types.d.ts @@ -1,5 +1,5 @@ import type { Component, SlotProps } from '../component'; -import type { DarkElement } from '../shared'; +import type { DarkElement, Subscribe, SubscriberWithValue } from '../shared'; export declare type ContexProviderProps = { value: T; } & SlotProps; @@ -11,5 +11,6 @@ export declare type Context = { }; export declare type ContextProviderValue = { value: T; - subscribers: Array<(value: T) => void>; + subscribers: Set<(value: T) => void>; + subscribe: Subscribe>; }; diff --git a/packages/core/types/helpers/index.d.ts b/packages/core/types/helpers/index.d.ts index bc5533c6..a125e88b 100644 --- a/packages/core/types/helpers/index.d.ts +++ b/packages/core/types/helpers/index.d.ts @@ -1,4 +1,4 @@ -import type { NestedArray } from '../shared'; +import type { NestedArray, DarkElementKey } from '../shared'; declare const detectIsFunction: (o: any) => o is Function; declare const detectIsUndefined: (o: any) => o is undefined; declare const detectIsNumber: (o: any) => o is number; @@ -19,6 +19,7 @@ declare function keyBy( declare function fromEnd(source: Array, count: number): T[]; declare const dummyFn: () => void; declare function detectIsDepsDifferent(deps: Array, prevDeps: Array): boolean; +declare function getDiffKeys(prevKeys: Array, nextKeys: Array): Array; export { detectIsFunction, detectIsUndefined, @@ -36,4 +37,5 @@ export { fromEnd, dummyFn, detectIsDepsDifferent, + getDiffKeys, }; diff --git a/packages/core/types/index.d.ts b/packages/core/types/index.d.ts index 148ffe32..76bf8819 100644 --- a/packages/core/types/index.d.ts +++ b/packages/core/types/index.d.ts @@ -1,16 +1,16 @@ export * from './component'; -export * from './context'; +export { createContext } from './context'; export { h } from './element'; export * from './fiber'; -export * from './fragment'; +export { Fragment } from './fragment'; export * from './platform'; export * from './helpers'; -export * from './lazy'; -export * from './memo'; +export { lazy } from './lazy'; +export { memo } from './memo'; export * from './ref'; export * from './scope'; export * from './shared'; -export * from './suspense'; +export { Suspense } from './suspense'; export { useCallback } from './use-callback'; export { useContext } from './use-context'; export { useDeferredValue } from './use-deferred-value'; @@ -31,6 +31,7 @@ export { useSyncExternalStore } from './use-sync-external-store'; export { walkFiber } from './walk'; export { unmountRoot } from './unmount'; export { batch } from './batch'; +export { SplitUpdate, useSplitUpdate } from './split-update'; export * from './view'; export * from './constants'; export declare const version: string; diff --git a/packages/core/types/shared/types.d.ts b/packages/core/types/shared/types.d.ts index f18a5723..0e28f6f6 100644 --- a/packages/core/types/shared/types.d.ts +++ b/packages/core/types/shared/types.d.ts @@ -8,3 +8,7 @@ export declare type NestedArray = T | Array>; export declare type RenderProps = (...args: Array) => DarkElement; export declare type DarkElementKey = string | number; export declare type DarkElementInstance = VirtualNode | VirtualNodeFactory | ComponentFactory; +export declare type Subscriber = () => void; +export declare type SubscriberWithValue = (value: T) => void; +export declare type Subscribe = (subscriber: S) => Unsubscribe; +export declare type Unsubscribe = () => void; diff --git a/packages/core/types/split-update/index.d.ts b/packages/core/types/split-update/index.d.ts new file mode 100644 index 00000000..95f1821b --- /dev/null +++ b/packages/core/types/split-update/index.d.ts @@ -0,0 +1 @@ +export * from './split-update'; diff --git a/packages/core/types/split-update/split-update.d.ts b/packages/core/types/split-update/split-update.d.ts new file mode 100644 index 00000000..eefcf560 --- /dev/null +++ b/packages/core/types/split-update/split-update.d.ts @@ -0,0 +1,16 @@ +import type { DarkElementKey, DarkElement } from '../shared'; +import { type ComponentFactory, type StandardComponentProps } from '../component'; +import { type Ref } from '../ref'; +declare type SplitUpdateProps = { + list: Array; + getKey: (x: T) => DarkElementKey; + slot: DarkElement; +}; +declare const SplitUpdate: SplitUpdate; +declare function useSplitUpdate( + selector: (map: Record) => T, + detectChange: (x: T) => DarkElementKey, +): T; +declare type MergedProps = SplitUpdateProps & StandardComponentProps; +declare type SplitUpdate = (props?: MergedProps, ref?: Ref) => ComponentFactory>; +export { SplitUpdate, useSplitUpdate }; diff --git a/packages/core/types/use-sync-external-store/use-sync-external-store.d.ts b/packages/core/types/use-sync-external-store/use-sync-external-store.d.ts index 761fc157..70a49c86 100644 --- a/packages/core/types/use-sync-external-store/use-sync-external-store.d.ts +++ b/packages/core/types/use-sync-external-store/use-sync-external-store.d.ts @@ -1,4 +1,3 @@ -declare type Subscribe = (cb: () => void) => Unsubscribe; -declare type Unsubscribe = () => void; -declare function useSyncExternalStore(subscribe: Subscribe, getSnapshot: () => T): T; +import type { Subscribe, Subscriber } from '../shared'; +declare function useSyncExternalStore(subscribe: Subscribe, getSnapshot: () => T): T; export { useSyncExternalStore }; diff --git a/packages/platform-browser/package.json b/packages/platform-browser/package.json index dd98e36c..a506b057 100644 --- a/packages/platform-browser/package.json +++ b/packages/platform-browser/package.json @@ -1,6 +1,6 @@ { "name": "@dark-engine/platform-browser", - "version": "0.11.2", + "version": "0.12.0", "description": "Dark is lightweight (10 Kb gzipped) component-and-hook-based UI rendering engine for javascript apps without dependencies and written in TypeScript 💫", "author": "AlexPlex", "license": "MIT",