-
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.
refactor: bind effect to render context
- Loading branch information
1 parent
034af0a
commit 6e4c309
Showing
13 changed files
with
1,904 additions
and
1,476 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
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.30", | ||
"version": "0.0.31", | ||
"main": "dist/index.js", | ||
"repository": "https://github.com/sahabpardaz/react-store.git", | ||
"author": "Amir Hossein Qasemi Moqaddam <[email protected]>", | ||
|
@@ -17,49 +17,50 @@ | |
"react-dom": "^17.0.0 || ^18.0.0" | ||
}, | ||
"devDependencies": { | ||
"@babel/plugin-proposal-class-properties": "^7.16.7", | ||
"@babel/plugin-proposal-decorators": "^7.17.9", | ||
"@babel/plugin-transform-runtime": "^7.17.0", | ||
"@babel/preset-env": "^7.16.11", | ||
"@babel/preset-react": "^7.16.7", | ||
"@babel/preset-typescript": "^7.16.7", | ||
"@commitlint/cli": "^16.2.3", | ||
"@commitlint/config-conventional": "^16.2.1", | ||
"@babel/plugin-proposal-class-properties": "^7.17.12", | ||
"@babel/plugin-proposal-decorators": "^7.18.2", | ||
"@babel/plugin-transform-runtime": "^7.18.5", | ||
"@babel/preset-env": "^7.18.2", | ||
"@babel/preset-react": "^7.17.12", | ||
"@babel/preset-typescript": "^7.17.12", | ||
"@commitlint/cli": "^17.0.2", | ||
"@commitlint/config-conventional": "^17.0.2", | ||
"@testing-library/jest-dom": "^5.16.4", | ||
"@testing-library/react": "^13.1.1", | ||
"@testing-library/react": "^13.3.0", | ||
"@trivago/prettier-plugin-sort-imports": "^3.2.0", | ||
"@types/clone-deep": "^4.0.1", | ||
"@types/jest": "^27.4.1", | ||
"@types/lodash": "^4.14.181", | ||
"@types/react": "^18.0.5", | ||
"@types/react-dom": "^18.0.1", | ||
"@types/jest": "^28.1.1", | ||
"@types/lodash": "^4.14.182", | ||
"@types/react": "^18.0.12", | ||
"@types/react-dom": "^18.0.5", | ||
"@types/styled-components": "^5.1.25", | ||
"@types/testing-library__jest-dom": "^5.14.3", | ||
"@typescript-eslint/eslint-plugin": "^5.19.0", | ||
"@typescript-eslint/parser": "^5.19.0", | ||
"@typescript-eslint/eslint-plugin": "^5.27.1", | ||
"@typescript-eslint/parser": "^5.27.1", | ||
"@zerollup/ts-transform-paths": "^1.7.18", | ||
"babel-jest": "^27.5.1", | ||
"babel-jest": "^28.1.1", | ||
"babel-plugin-transform-typescript-metadata": "^0.3.2", | ||
"eslint": "^8.13.0", | ||
"eslint": "^8.17.0", | ||
"eslint-config-prettier": "^8.5.0", | ||
"html-webpack-plugin": "^5.5.0", | ||
"husky": "^7.0.4", | ||
"jest": "^27.5.1", | ||
"lint-staged": ">=12", | ||
"husky": "^8.0.1", | ||
"jest": "^28.1.1", | ||
"jest-environment-jsdom": "^28.1.1", | ||
"lint-staged": ">=13", | ||
"prettier": "^2.6.2", | ||
"react": "^18.0.0", | ||
"react-dom": "^18.0.0", | ||
"react-refresh-typescript": "^2.0.4", | ||
"react": "^18.1.0", | ||
"react-dom": "^18.1.0", | ||
"react-refresh-typescript": "^2.0.5", | ||
"react-router-dom": "6", | ||
"rollup": "^2.70.2", | ||
"rollup-plugin-typescript2": "^0.31.2", | ||
"rollup": "^2.75.6", | ||
"rollup-plugin-typescript2": "^0.32.1", | ||
"styled-components": "^5.3.5", | ||
"ts-loader": "^9.2.8", | ||
"ts-loader": "^9.3.0", | ||
"ttypescript": "^1.5.13", | ||
"typescript": "^4.6.3", | ||
"webpack": "^5.72.0", | ||
"webpack-cli": "^4.9.2", | ||
"webpack-dev-server": "^4.8.1", | ||
"typescript": "^4.7.3", | ||
"webpack": "^5.73.0", | ||
"webpack-cli": "^4.10.0", | ||
"webpack-dev-server": "^4.9.2", | ||
"websocket-extensions": "^0.1.4" | ||
}, | ||
"scripts": { | ||
|
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,4 +1,3 @@ | ||
export const TARGET = Symbol("TARGET"); | ||
export const STORE_USED_CONTEXTS = Symbol("STORE_USED_CONTEXTS"); | ||
export const STORE_ADMINISTRATION = Symbol("STORE_ADMINISTRATION"); | ||
export const PROXY_HANDLER_TYPE = Symbol("PROXY_HANDLER_TYPE"); |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
import { StoreAdministrator } from "../storeAdministrator"; | ||
import { adtProxyBuilder } from "src/proxy/adtProxy/adtProxyBuilder"; | ||
import { getUnproxiedValue } from "src/utils/getUnProxiedValue"; | ||
|
||
export class EffectProxy implements ProxyHandler<object> { | ||
directMutatedStoreProperties = new Map<PropertyKey, unknown>(); | ||
|
||
constructor(private storeAdmin: StoreAdministrator) {} | ||
|
||
get(target: object, propertyKey: PropertyKey, receiver: unknown) { | ||
if (this.directMutatedStoreProperties.has(propertyKey)) { | ||
return this.directMutatedStoreProperties.get(propertyKey); | ||
} | ||
|
||
// Property Key | ||
if (this.storeAdmin?.propertyKeysManager.propertyKeys.has(propertyKey)) { | ||
const value = this.storeAdmin?.propertyKeysManager.propertyKeys | ||
.get(propertyKey) | ||
?.getValue("State"); | ||
|
||
if (StoreAdministrator.get(getUnproxiedValue(value))) { | ||
return StoreAdministrator.get(getUnproxiedValue(value))?.effectsManager | ||
.context; | ||
} | ||
|
||
return adtProxyBuilder({ | ||
value, | ||
proxiedValuesStorage: new Map(), | ||
onSet: () => | ||
this.storeAdmin.propertyKeysManager.propertyKeys | ||
.get(propertyKey) | ||
?.doOnSet(), | ||
}); | ||
} | ||
|
||
// Getters | ||
if (this.storeAdmin?.gettersManager.getters.has(propertyKey)) { | ||
return this.storeAdmin.gettersManager.getters | ||
.get(propertyKey) | ||
?.getValue("State"); | ||
} | ||
|
||
/** | ||
* There is no need to bind methods to effect context because when we call method in | ||
* effect context using this keyword, the method is automatically bind to effect context | ||
*/ | ||
|
||
return Reflect.get(target, propertyKey, receiver); | ||
} | ||
|
||
set(target: object, propertyKey: PropertyKey, value: unknown) { | ||
this.storeAdmin?.propertyKeysManager.onSetPropertyKey(propertyKey, value); | ||
this.directMutatedStoreProperties.set(propertyKey, value); | ||
return true; | ||
} | ||
} |
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
Oops, something went wrong.