Skip to content

Commit

Permalink
sync update code
Browse files Browse the repository at this point in the history
  • Loading branch information
lsbFlying committed Oct 13, 2024
1 parent e245174 commit e3754d6
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 23 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -348,10 +348,10 @@ class AppClass extends ComponentWithStore {
<>
<span>{userName}</span>
<span>{theme}</span>
<button onClick={() => { this.userStore.userName = "LD" }}>
<button onClick={() => { userStore.userName = "LD" }}>
nameChange
</button>
<button onClick={() => { this.themeStore.setState({ theme: "light" }) }}>
<button onClick={() => { themeStore.setState({ theme: "light" }) }}>
themeChange
</button>
</>
Expand Down
6 changes: 2 additions & 4 deletions src/classConnect/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { ConnectStoreType, ClassConnectStoreType, ClassStoreType } from "./types";
import type { ClassConnectStoreType, ClassStoreType } from "./types";
import type { ValueOf, PrimitiveState } from "../types";
import type { ConciseStoreCore, Store } from "../store/types";
import { Component, PureComponent } from "react";
Expand All @@ -10,7 +10,6 @@ import { connectStoreCore, constructorProcessing } from "./core";
/**
* @class ComponentWithStore
* @classdesc The public base class can connect to the store
* @implements ConnectStoreType
*/
export class ComponentWithStore<
P extends PrimitiveState = {},
Expand Down Expand Up @@ -38,13 +37,12 @@ export class ComponentWithStore<
/**
* @class PureComponentWithStore
* @classdesc The public base class can connect to the store
* @implements ConnectStoreType
*/
export class PureComponentWithStore<
P extends PrimitiveState = {},
S extends PrimitiveState = {},
SS = any,
> extends PureComponent<P, S, SS> implements ConnectStoreType {
> extends PureComponent<P, S, SS> {
constructor(props: P) {
super(props);
constructorProcessing.apply(this as any);
Expand Down
17 changes: 1 addition & 16 deletions src/classConnect/types.ts
Original file line number Diff line number Diff line change
@@ -1,25 +1,10 @@
import type { PrimitiveState } from "../types";
import type { ConciseStoreCore, SetOptions, State, Store, StoreCoreUtils } from "../store/types";
import type { SetOptions, State, Store, StoreCoreUtils } from "../store/types";
import {
__CLASS_INITIAL_STATE_RETRIEVE_KEY__, __CLASS_THIS_POINTER_STORES_KEY__,
__CLASS_STATE_REF_SET_KEY__, __CLASS_UNMOUNT_PROCESSING_KEY__, __CLASS_CONNECT_STORE_KEY__,
} from "./static";

/**
* @description This is an important method that is core to the functionality of this class.
* Performs some action. This method should not be overridden in subclasses.
* Even if you rewrite it, your rewriting method should be like this below:
* connectStore<S extends PrimitiveState>(store: S): S & SetOptions & StoreCoreUtils<S> {
* ...
* return super.connectStore(store);
* }
* @interface connectStore
* @param store
*/
export type ConnectStoreType = Readonly<{
connectStore<S extends PrimitiveState>(store: Store<S> | ConciseStoreCore<S>): ClassStoreType<S>;
}>;

/** This is the data type returned by the class after connecting to the store */
export type ClassStoreType<S extends PrimitiveState> = S & StoreCoreUtils<S> & Readonly<SetOptions>;

Expand Down
2 changes: 1 addition & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@ export { useSubscription } from "./subscribe";
export * from "./subscribe/types";

export { ComponentWithStore, PureComponentWithStore } from "./classConnect";
export type { ConnectStoreType, ClassStoreType } from "./classConnect/types";
export type { ClassStoreType } from "./classConnect/types";

export * from "./types";

0 comments on commit e3754d6

Please sign in to comment.