-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1c3ab80
commit 51ca2ed
Showing
11 changed files
with
128 additions
and
115 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
{ | ||
"name": "@react-store/core", | ||
"version": "0.0.32", | ||
"version": "0.0.33", | ||
"main": "dist/index.js", | ||
"repository": "https://github.com/sahabpardaz/react-store.git", | ||
"author": "Amir Hossein Qasemi Moqaddam <[email protected]>", | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import { StoreAdministrator } from "../storeAdministrator"; | ||
|
||
/** | ||
* Effect context must be proxied to use value from state insteadOf store | ||
* because we have hooks like useDeferredValue or useTransition can others hooks cause | ||
* rerenders but these hooks value not change in that render | ||
* So we must bind effect context to state values. | ||
*/ | ||
export class MethodProxyHandler implements ProxyHandler<object> { | ||
directMutatedStoreProperties = new Map<PropertyKey, unknown>(); | ||
|
||
constructor(private storeAdmin: StoreAdministrator) {} | ||
|
||
get(target: object, propertyKey: PropertyKey, receiver: unknown) { | ||
/** | ||
* Because we change effect context to state if we set value it will be | ||
* done async and if we read the value immediately it doesn't work | ||
* so we make trick here only for primitive types | ||
*/ | ||
if (this.directMutatedStoreProperties.has(propertyKey)) { | ||
return this.directMutatedStoreProperties.get(propertyKey); | ||
} | ||
|
||
if (this.storeAdmin?.propertyKeysManager.propertyKeys.has(propertyKey)) { | ||
return this.storeAdmin?.propertyKeysManager.propertyKeys | ||
.get(propertyKey) | ||
?.getValue("State", false); | ||
} | ||
|
||
// Getters | ||
if (this.storeAdmin?.gettersManager.getters.has(propertyKey)) { | ||
return this.storeAdmin.gettersManager.getters | ||
.get(propertyKey) | ||
?.getValue("State"); | ||
} | ||
|
||
return Reflect.get(target, propertyKey, receiver); | ||
} | ||
|
||
set(_: object, propertyKey: PropertyKey, value: unknown) { | ||
if (this.storeAdmin?.propertyKeysManager.onSetPropertyKey(propertyKey, value)) { | ||
this.directMutatedStoreProperties.set(propertyKey, value); | ||
} | ||
return true; | ||
} | ||
} |
21 changes: 17 additions & 4 deletions
21
...tore/administrator/storeMethodsManager.ts → ...inistrator/methods/storeMethodsManager.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters