Skip to content

Commit

Permalink
[State] Fix for infinite loading bug with persist
Browse files Browse the repository at this point in the history
  • Loading branch information
Pckool committed Aug 21, 2022
1 parent ee03f87 commit b65d57b
Show file tree
Hide file tree
Showing 10 changed files with 26 additions and 28 deletions.
3 changes: 2 additions & 1 deletion nx.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
{
"extends": "nx/presets/npm.json",
"tasksRunnerOptions": {
"default": {
"runner": "nx/tasks-runners/default",
"options": {
"cacheableOperations": []
"cacheableOperations": ["build"]
}
}
},
Expand Down
6 changes: 3 additions & 3 deletions packages/plexus-api/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@plexusjs/api",
"version": "1.3.5-canary.5+1b9bbde",
"version": "1.3.5-canary.7+ee03f87",
"description": "A library for building modular interconnected applications",
"main": "./dist/index.js",
"types": "dist/index.d.ts",
Expand All @@ -23,11 +23,11 @@
"prepublish": "yarn build",
"dev": "tsc --watch"
},
"gitHead": "1b9bbdedc9a5e4e9c8fb6e92b247dabb8d6a303e",
"gitHead": "ee03f87c50fa3dbc75aac64fdfb5c948fce40a63",
"devDependencies": {
"isomorphic-fetch": "^3.0.0"
},
"dependencies": {
"@plexusjs/utils": "1.3.5-canary.5+1b9bbde"
"@plexusjs/utils": "1.3.5-canary.7+ee03f87"
}
}
8 changes: 4 additions & 4 deletions packages/plexus-core/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@plexusjs/core",
"version": "1.3.5-canary.5+1b9bbde",
"version": "1.3.5-canary.7+ee03f87",
"description": "A library for building modular interconnected applications",
"main": "./dist/index.js",
"types": "dist/index.d.ts",
Expand All @@ -23,12 +23,12 @@
"prepublish": "yarn build",
"dev": "tsc --watch"
},
"gitHead": "1b9bbdedc9a5e4e9c8fb6e92b247dabb8d6a303e",
"gitHead": "ee03f87c50fa3dbc75aac64fdfb5c948fce40a63",
"devDependencies": {
"isomorphic-fetch": "^3.0.0"
},
"dependencies": {
"@plexusjs/api": "1.3.5-canary.5+1b9bbde",
"@plexusjs/utils": "1.3.5-canary.5+1b9bbde"
"@plexusjs/api": "1.3.5-canary.7+ee03f87",
"@plexusjs/utils": "1.3.5-canary.7+ee03f87"
}
}
3 changes: 0 additions & 3 deletions packages/plexus-core/src/collection/data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,6 @@ export class CollectionDataInstance<DataType extends DataObjectType<PK> = any, P
if (!this.instance()._collectionData.has(this)) {
this.instance()._collectionData.add(this)
this.instance().runtime.log("info", `Hoisting collection data ${this.instanceId} with value`, this._watchableStore._value, `to instance`)
// if (this._internalStore._persist) {
// this.instance().storage?.sync()
// }
}
}

Expand Down
6 changes: 2 additions & 4 deletions packages/plexus-core/src/state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,16 +51,14 @@ export class StateInstance<StateValue extends PlexusStateType> extends Watchable

private persistSync() {
if (this._internalStore._persist) {
this.instance().storage?.sync()
this.instance().storage?.sync(this._watchableStore._value)
}
}
private mount() {
if (!this.instance()._states.has(this)) {
this.instance()._states.add(this)
this.instance().runtime.log("debug", `Hoisting state ${this.instanceId} with value`, this._watchableStore._value, `to instance`)
if (this._internalStore._persist) {
this.instance().storage?.sync()
}
this.persistSync()
}
if (this._internalStore._ready) return
this._internalStore._ready = true
Expand Down
8 changes: 5 additions & 3 deletions packages/plexus-core/src/storage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,8 @@ export class StorageInstance {
this.instance().storage?.set(key, object.value)
}
}
sync() {
this.instance().runtime.log("info", "Syncing storage storage...")
sync(checkValue?: any) {
this.instance().runtime.log("info", "Syncing storage...")
this._internalStore.tracking.forEach((object) => {
let key: string | null = null
if (typeof object?.key === "string") {
Expand All @@ -143,7 +143,7 @@ export class StorageInstance {
let storedValue = this.get(key)

if (storedValue) {
const val = object.value
const val = checkValue ?? object.value
if (!isEqual(val, storedValue)) {
this.instance().runtime.log(
"info",
Expand All @@ -158,6 +158,8 @@ export class StorageInstance {
)}"] storage["${convertThingToString(storedValue)}"])`
)
}
} else {
this.instance().runtime.log("warn", `Can't sync with storage; No Stored Value found`)
}
})
}
Expand Down
4 changes: 2 additions & 2 deletions packages/plexus-next/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@plexusjs/next",
"version": "1.3.5-canary.5+1b9bbde",
"version": "1.3.5-canary.7+ee03f87",
"description": "Next Plugin for PlexusJS",
"main": "./dist/index.js",
"types": "dist/index.d.ts",
Expand Down Expand Up @@ -36,5 +36,5 @@
"prepublish": "yarn build",
"dev": "tsc --watch"
},
"gitHead": "1b9bbdedc9a5e4e9c8fb6e92b247dabb8d6a303e"
"gitHead": "ee03f87c50fa3dbc75aac64fdfb5c948fce40a63"
}
6 changes: 3 additions & 3 deletions packages/plexus-react/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@plexusjs/react",
"version": "1.3.5-canary.5+1b9bbde",
"version": "1.3.5-canary.7+ee03f87",
"description": "React Plugin for PlexusJS",
"main": "./dist/index.js",
"types": "dist/index.d.ts",
Expand Down Expand Up @@ -34,9 +34,9 @@
"prepublish": "yarn build",
"dev": "tsc --watch"
},
"gitHead": "1b9bbdedc9a5e4e9c8fb6e92b247dabb8d6a303e",
"gitHead": "ee03f87c50fa3dbc75aac64fdfb5c948fce40a63",
"dependencies": {
"@plexusjs/utils": "1.3.5-canary.5+1b9bbde",
"@plexusjs/utils": "1.3.5-canary.7+ee03f87",
"use-sync-external-store": "^1.2.0"
}
}
6 changes: 3 additions & 3 deletions packages/plexus-solid/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@plexusjs/solid",
"version": "1.3.5-canary.5+1b9bbde",
"version": "1.3.5-canary.7+ee03f87",
"description": "SolidJS Plugin for PlexusJS",
"main": "./dist/index.js",
"types": "dist/index.d.ts",
Expand All @@ -26,9 +26,9 @@
"prepublish": "yarn build",
"dev": "tsc --watch"
},
"gitHead": "1b9bbdedc9a5e4e9c8fb6e92b247dabb8d6a303e",
"gitHead": "ee03f87c50fa3dbc75aac64fdfb5c948fce40a63",
"dependencies": {
"@plexusjs/utils": "1.3.5-canary.5+1b9bbde",
"@plexusjs/utils": "1.3.5-canary.7+ee03f87",
"solid-js": "^1.4.7"
}
}
4 changes: 2 additions & 2 deletions packages/plexus-utils/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@plexusjs/utils",
"version": "1.3.5-canary.5+1b9bbde",
"version": "1.3.5-canary.7+ee03f87",
"description": "Useful utils by the PlexusJS Team.",
"main": "./dist/index.js",
"types": "dist/index.d.ts",
Expand All @@ -23,5 +23,5 @@
"prepublish": "yarn build",
"dev": "tsc --watch"
},
"gitHead": "1b9bbdedc9a5e4e9c8fb6e92b247dabb8d6a303e"
"gitHead": "ee03f87c50fa3dbc75aac64fdfb5c948fce40a63"
}

0 comments on commit b65d57b

Please sign in to comment.