Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 22 additions & 6 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,8 @@
"test:watch": "eslint --fix && jest --updateSnapshot --watchAll"
},
"types": "dist/index.d.ts",
"version": "6.0.6",
"version": "7.0.0",
"dependencies": {
"@webkrafters/auto-immutable": "^2.0.5"
"@webkrafters/eagleeye": "^1.0.0-beta.4"
}
}
14 changes: 0 additions & 14 deletions src/constants.ts

This file was deleted.

210 changes: 36 additions & 174 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,10 @@ import type {
ForwardRefExoticComponent,
MemoExoticComponent,
NamedExoticComponent,
ReactNode,
PropsWithoutRef,
RefAttributes
} from 'react';

import type {
Changes as BaseChanges,
Connection,
Immutable,
Value
} from '@webkrafters/auto-immutable';

import { FULL_STATE_SELECTOR } from './constants';

export type {
BaseType,
ClearCommand,
Expand All @@ -33,26 +23,42 @@ export type {
UpdatePayloadArray
} from '@webkrafters/auto-immutable';

export type State = Value;

export type Listener<T extends State = {}> = (
changes : Changes<T>,
changedPathsTokens : Readonly<Array<Array<string>>>,
netChanges : Readonly<T>,
mayHaveChangesAt : (pathTokens : Array<string>) => boolean
) => void;

export type ObservableProvider<T extends State> = ForwardRefExoticComponent<
ProviderProps<T> &
RefAttributes<StoreRef<T>>
>;
export type {
ArraySelector,
Changes,
Channel,
Data,
FullStateSelector,
IStorage,
IStore,
Listener,
ObjectSelector,
Prehooks,
ProviderProps,
SelectorMap,
State,
Store,
StoreInternal,
StoreRef,
Stream,
Text,
Unsubscribe
} from '@webkrafters/eagleeye';

import { SelectorMap, State, Store } from '@webkrafters/eagleeye';

export interface ProviderProps<T extends State> {
children?: ReactNode;
prehooks?: Prehooks<T>;
storage?: IStorage<T>;
value: PartialState<T>;
};
export {
CLEAR_TAG,
DELETE_TAG,
FULL_STATE_SELECTOR,
MOVE_TAG,
NULL_SELECTOR,
PUSH_TAG,
REPLACE_TAG,
SET_TAG,
SPLICE_TAG,
Tag,
} from '@webkrafters/eagleeye';

export type ConnectProps<
OWNPROPS extends OwnProps = IProps,
Expand Down Expand Up @@ -82,152 +88,8 @@ export type ExtractInjectedProps<
ALL_PROPS extends OwnProps = OwnProps
> = Omit<ALL_PROPS, keyof Store<STATE>|keyof SELECTOR_MAP>


export interface IProps { ref?: unknown }

export type OwnProps = IProps & Record<any, any>;

export type Text = string | number;

export type FullStateSelector = typeof FULL_STATE_SELECTOR;

export type ObjectSelector = Record<Text, Text | FullStateSelector>;

export type ArraySelector = Array<Text | FullStateSelector>;

export type SelectorMap = ObjectSelector | ArraySelector | void;

type ReplacePathSeps<
P extends Text,
T extends string,
> = P extends `${infer U}${T}${infer V}`
? ReplacePathSeps<`${U}.${V}`, T>
: P;

type TrimPathSep<P extends Text> = P extends `${infer U}]${never}` ? U : P;

type NormalizePath<P extends Text> = TrimPathSep<
ReplacePathSeps<
ReplacePathSeps<
ReplacePathSeps<
P,
']['
>,
'].'
>,
'['
>
>;

type Datum<
P extends Text,
S extends Record<Text, any> = State
> = P extends `${infer K}.${infer P_1}`
? Datum<P_1, S[K]>
: P extends ''
? S
: any;

type DataPoint<
P extends Text,
S extends State
> = P extends FullStateSelector ? S : Datum<NormalizePath<P>, S>;

export type Data<
SELECTOR_MAP extends SelectorMap,
STATE extends State = State
> = (
SELECTOR_MAP extends ObjectSelector
? {[ S_KEY in keyof SELECTOR_MAP ] : DataPoint<SELECTOR_MAP[S_KEY], STATE> }
: SELECTOR_MAP extends ArraySelector
? {[ S_NUM : number ] : DataPoint<SELECTOR_MAP[number], STATE>}
: Array<any>
);

export type Changes<T extends State = State> = BaseChanges<T>;

export interface IStorage<T extends State = State> {
clone: (data: T) => T;
getItem: (key: string) => T;
removeItem: (key: string) => void;
setItem: (key: string, data: T) => void;
};

export type NonReactUsageReport = (...args: Array<unknown>) => void;

export type PartialState<T extends State> = T extends Partial<infer U> ? T : Partial<T>;

export interface Prehooks<T extends State = State> {
resetState?: (
resetData: PartialState<T>,
state: {
current: T;
original: T;
}
) => boolean;
setState?: (newChanges: Changes<T>) => boolean;
};

export type Subscribe = <T extends State>( listener : Listener<T> ) => Unsubscribe;

export type Unsubscribe = (...args: Array<unknown>) => void;

export interface IStore {
resetState: Function;
setState: Function;
}

export interface IStoreInternal extends IStore {
subscribe: Function;
}

export interface Store<
T extends State,
SELECTOR_MAP extends SelectorMap = SelectorMap
> extends IStore {
data: Data<SELECTOR_MAP>;
resetState: (propertyPaths?: Array<string>) => void;
setState: (changes: Changes<T>) => void;
};

export interface StoreInternal<T extends State> extends IStoreInternal {
cache: Immutable<Partial<T>>,
resetState: (connection: Connection<T>, propertyPaths?: Array<string>) => void;
setState: (connection: Connection<T>, changes: Changes<T>) => void;
subscribe: Subscribe;
};

export interface StorePlaceholder extends IStoreInternal {
getState: NonReactUsageReport;
resetState: NonReactUsageReport;
setState: NonReactUsageReport;
subscribe: NonReactUsageReport;
};

export interface StoreRef<T extends State = State> extends StorePlaceholder {
getState: (propertyPaths?: Array<string>) => T,
resetState: (propertyPaths?: Array<string>) => void;
setState: (changes: Changes<T>) => void;
subscribe: Subscribe;
}

export {
CLEAR_TAG,
DELETE_TAG,
FULL_STATE_SELECTOR,
MOVE_TAG,
NULL_SELECTOR,
PUSH_TAG,
REPLACE_TAG,
SET_TAG,
SPLICE_TAG,
Tag,
} from './constants';

export {
connect,
createContext,
ObservableContext,
UsageError,
useContext
} from './main';
export { createContext as createEagleEye } from './main';
19 changes: 0 additions & 19 deletions src/main/hooks/use-prehooks-ref/index.test.ts

This file was deleted.

12 changes: 0 additions & 12 deletions src/main/hooks/use-prehooks-ref/index.ts

This file was deleted.

Loading