diff --git a/README.md b/README.md index f17ec2f..ce42fae 100644 --- a/README.md +++ b/README.md @@ -1,19 +1,19 @@ -

Dox logo

+

Dobux logo

-

Dox

+

Dobux

- this is the description of dox + 轻量级的响应式状态管理方案

- Build Status - Coverage Status - Version - Downloads - Bundle Size - Vulnerabilities + Build Status + Coverage Status + Version + Downloads + Bundle Size + Vulnerabilities
- Peer React - Peer React Dom + Peer React + Peer React Dom

## ✨ 特性 @@ -24,11 +24,11 @@ ## 📦 安装 ```bash -$ npm i dox-test -S +$ npm i dobux -S ``` ```bash -$ yarn add dox-test +$ yarn add dobux ``` ## 🔨 快速开始 diff --git a/package.json b/package.json index 839e1b4..6c7860c 100644 --- a/package.json +++ b/package.json @@ -33,7 +33,7 @@ }, "repository": { "type": "git", - "url": "https://github.com/kwai-ad-fe/dobux" + "url": "https://github.com/kwai-efe/dobux" }, "keywords": [ "react", @@ -68,6 +68,9 @@ ] } }, + "dependencies": { + "immer": "^6.0.9" + }, "peerDependencies": { "react": "^16.8.0", "react-dom": "^16.8.0" diff --git a/scripts/conventional-changelog-config/writer-opts.js b/scripts/conventional-changelog-config/writer-opts.js index 2aa994f..845f622 100644 --- a/scripts/conventional-changelog-config/writer-opts.js +++ b/scripts/conventional-changelog-config/writer-opts.js @@ -40,22 +40,22 @@ function getWriterOpts() { commit.type = `⚡ Performance Improvements` } else if (commit.type === `revert`) { commit.type = `⏪ Reverts` - } else if (commit.type === `docs`) { - commit.type = `📖 Documentation` - } else if (commit.type === `style`) { - commit.type = `💄 Styles` } else if (commit.type === `refactor`) { commit.type = `♻ Code Refactoring` } else if (commit.type === `test`) { commit.type = `✅ Tests` + } else if (discard) { + return + } else if (commit.type === `docs`) { + commit.type = `📖 Documentation` + } else if (commit.type === `style`) { + commit.type = `💄 Styles` } else if (commit.type === `build`) { commit.type = `📦 Build System` } else if (commit.type === `ci`) { commit.type = `🔧 Continuous Integration` } else if (commit.type === 'chore') { commit.type = '⚙️ Chores' - } else if (discard) { - return } if (commit.scope === '*') { diff --git a/scripts/release.js b/scripts/release.js index 96d30b1..debcf50 100644 --- a/scripts/release.js +++ b/scripts/release.js @@ -79,7 +79,7 @@ async function publishToNpm(nextVersion) { } async function githubRelease(tag, body, isPrerelease) { - const repoUrl = repository ? repository.url : 'https://github.com/kwai-ad-fe/dobux' + const repoUrl = repository ? repository.url : 'https://github.com/kwai-efe/dobux' const url = newGithubReleaseUrl({ repoUrl, tag, diff --git a/src/types.ts b/src/types.ts new file mode 100644 index 0000000..e055c74 --- /dev/null +++ b/src/types.ts @@ -0,0 +1,168 @@ +import { Dispatch } from 'react' + +type Push = ((r: any, ...x: L) => void) extends (...x: infer L2) => void + ? { [K in keyof L2]-?: K extends keyof L ? L[K] : T } + : never + +// convert a union to an intersection: X | Y | Z ==> X & Y & Z +type UnionToIntersection = (U extends any ? (k: U) => void : never) extends (k: infer I) => void + ? I + : never + +// convert a union to an overloaded function X | Y ==> ((x: X)=>void) & ((y:Y)=>void) +type UnionToOvlds = UnionToIntersection void : never> + +// convert a union to a tuple X | Y => [X, Y] +// a union of too many elements will become an array instead +type UnionToTuple = UTT0 extends infer T + ? T extends any[] + ? Exclude extends never + ? T + : U[] + : never + : never + +// each type function below pulls the last element off the union and +// pushes it onto the list it builds +type UTT0 = UnionToOvlds extends (a: infer A) => void ? Push>, A> : [] +type UTT1 = UnionToOvlds extends (a: infer A) => void ? Push>, A> : [] +type UTT2 = UnionToOvlds extends (a: infer A) => void ? Push>, A> : [] +type UTT3 = UnionToOvlds extends (a: infer A) => void ? Push>, A> : [] +type UTT4 = UnionToOvlds extends (a: infer A) => void ? Push>, A> : [] +type UTT5 = UnionToOvlds extends (a: infer A) => void ? Push>, A> : [] +type UTTX = [] + +export interface Noop { + (...args: any[]): R +} + +export interface ConfigReducer { + (state: S, ...payload: any): void +} + +export interface ConfigReducers { + [name: string]: ConfigReducer +} + +export interface ConfigEffect { + (...payload: any[]): any +} + +export interface ConfigEffects { + (model: M, rootModel: RM): { [key: string]: ConfigEffect } +} + +export interface Config { + state: S + reducers: ConfigReducers + effects: ConfigEffects +} + +export interface Configs { + [key: string]: Config +} + +interface ModelEffectState { + loading: boolean + identifier: number +} + +interface BuildInReducers { + setValue: (key: K, value: S[K]) => void + setValues: (state: Partial) => void + reset: (key?: K) => void +} + +type ModelReducer = MR extends (state: any, ...payload: infer P) => void + ? (...payload: P) => void + : any + +export type ModelReducers = { + [K in keyof R]: ModelReducer +} & + BuildInReducers + +export type ModelEffect = (E extends (...payload: infer P) => infer R + ? (...payload: P) => R + : any) & + ModelEffectState + +export type ModelEffects = { + [K in keyof C]: ModelEffect +} + +export interface Model { + state: S extends undefined ? C['state'] : S + reducers: R extends undefined + ? C['reducers'] extends ConfigReducers + ? ModelReducers + : BuildInReducers + : R + effects: E extends undefined + ? C['effects'] extends ConfigEffects + ? ModelEffects> + : Record + : E +} + +export type Models = { + [K in keyof C]: { + state: Model['state'] + reducers: Model['reducers'] + effects: Model['effects'] + } +} + +export interface ModelConfig { + state: S + reducers: ConfigReducers + effects: { [key: string]: ConfigEffect } +} + +export interface ContextPropsModel { + state: C['state'] + reducers: C['reducers'] extends ConfigReducers + ? ModelReducers + : BuildInReducers + effects: C['effects'] extends ConfigEffects + ? ModelEffects> + : Record +} + +export interface ModelProviderOptions { + autoReset?: boolean + devTools?: boolean +} + +export interface ModelContextProps { + model: ContextPropsModel + options: ModelProviderOptions +} + +export type ModelProvider = React.FC> + +export interface StoreProviderOptions { + autoReset?: boolean | UnionToTuple + devTools?: boolean | UnionToTuple +} + +export type StoreProvider = React.FC< + React.PropsWithChildren> +> + +export type HOC =

( + Component: React.ComponentType

+) => React.ComponentType

+ +export type Optionality = Omit + +export interface Subscriber { + mapStateToProps: any + prevState: T + effects: any + dispatcher: Dispatch +} + +export interface MapStateToProps, S = any> { + (state: M['state']): S +}