From 4934e7b0f53268f7362869c55c135e75dfd049df Mon Sep 17 00:00:00 2001 From: Johannes Millan Date: Fri, 22 May 2020 16:21:58 +0200 Subject: [PATCH] chore(automerge): add lib again --- package.json | 1 + .../core/persistence/persistence.service.ts | 18 +++++++------ src/app/features/tag/store/tag.effects.ts | 4 +-- yarn.lock | 27 ++++++++++++++++++- 4 files changed, 39 insertions(+), 11 deletions(-) diff --git a/package.json b/package.json index f3ef5c806..0c495241d 100644 --- a/package.json +++ b/package.json @@ -121,6 +121,7 @@ "all-contributors-cli": "^6.8.0", "angular-material-css-vars": "^0.3.7", "angular2-promise-buttons": "latest", + "automerge": "^0.14.0", "chart.js": "^2.8.0", "clipboard": "^2.0.1", "codelyzer": "^5.1.2", diff --git a/src/app/core/persistence/persistence.service.ts b/src/app/core/persistence/persistence.service.ts index 5b951ad59..9cca30977 100644 --- a/src/app/core/persistence/persistence.service.ts +++ b/src/app/core/persistence/persistence.service.ts @@ -474,10 +474,7 @@ export class PersistenceService { console.log('----------------------------------------------------------------'); console.log(dbKey, actionName, this._automergeCache[dbKey]); if (!this._automergeCache[dbKey]) { - this._automergeCache[dbKey] = Automerge.from( - data, - {actorId: this._getActor()}, - ); + this._automergeCache[dbKey] = Automerge.from(data, this._getActor()); console.log('INIT IN SAVE', this._automergeCache[dbKey]); } @@ -518,18 +515,23 @@ export class PersistenceService { private async _loadFromDb(key: string): Promise { if (!this._automergeCache[key]) { const data = await this._databaseService.load(key); - console.log(key); - if (key !== 'TAG_STATE' && key !== 'TASKS_STATE') { + if ((key !== 'TAG_STATE' && key !== 'TASKS_STATE')) { return data || undefined; } - if (data) { + console.log(key, data); + + if (!data) { + return undefined; + } else if (typeof data === 'string') { this._automergeCache[key] = Automerge.load(data, this._getActor()); console.log('INIT_IN_LOAD--', key, this._automergeCache[key]); console.log(Automerge.getHistory(this._automergeCache[key]).map(state => [state.change.message])); return this._automergeCache[key]; + } else { + this._automergeCache[key] = Automerge.from(data, this._getActor()); + } - return undefined; } // NOTE: we use undefined as null does not trigger default function arguments diff --git a/src/app/features/tag/store/tag.effects.ts b/src/app/features/tag/store/tag.effects.ts index 327787bce..c206eeb44 100644 --- a/src/app/features/tag/store/tag.effects.ts +++ b/src/app/features/tag/store/tag.effects.ts @@ -65,7 +65,7 @@ export class TagEffects { TaskActionTypes.DeleteMainTasks, TaskActionTypes.UpdateTaskTags, ), - switchMap(() => this._saveToLs$), + switchMap((a) => this._saveToLs$(a)), ), {dispatch: false}); updateProjectStorageConditionalTask$ = createEffect(() => this._actions$.pipe( @@ -95,7 +95,7 @@ export class TagEffects { ? of(a) : EMPTY; }), - switchMap(() => this._saveToLs$), + switchMap((a) => this._saveToLs$(a)), ), {dispatch: false}); updateTagsStorageConditional$ = createEffect(() => this._actions$.pipe( diff --git a/yarn.lock b/yarn.lock index 44280aeae..f051ab179 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2026,6 +2026,16 @@ atob@^2.1.2: resolved "https://registry.yarnpkg.com/atob/-/atob-2.1.2.tgz#6d9517eb9e030d2436666651e86bd9f6f13533c9" integrity sha512-Wm6ukoaOGJi/73p/cl2GvLjTI5JM1k/O14isD73YML8StrH/7/lRFgmg8nICZgD3bZZvjwCGxtMOD3wWNAu8cg== +automerge@^0.14.0: + version "0.14.0" + resolved "https://registry.yarnpkg.com/automerge/-/automerge-0.14.0.tgz#cdee150385415812eb39d58a25bd9b74a46e0a8b" + integrity sha512-H0Lszio1ZywPpJ3bS8IZ8qGkmFYN/cLPXT30AD1gDz7LMd6NEhdbOA+uBLr97a4M4f3Xx0KtOAJrQ7Xjo4OCOQ== + dependencies: + immutable "^3.8.2" + transit-immutable-js "^0.7.0" + transit-js "^0.8.861" + uuid "^3.4.0" + autoprefixer@9.7.4: version "9.7.4" resolved "https://registry.yarnpkg.com/autoprefixer/-/autoprefixer-9.7.4.tgz#f8bf3e06707d047f0641d87aee8cfb174b2a5378" @@ -5821,6 +5831,11 @@ immediate@~3.0.5: resolved "https://registry.yarnpkg.com/immediate/-/immediate-3.0.6.tgz#9db1dbd0faf8de6fbe0f5dd5e56bb606280de69b" integrity sha1-nbHb0Pr43m++D13V5Wu2BigN5ps= +immutable@^3.8.2: + version "3.8.2" + resolved "https://registry.yarnpkg.com/immutable/-/immutable-3.8.2.tgz#c2439951455bb39913daf281376f1530e104adf3" + integrity sha1-wkOZUUVbs5kT2vKBN28VMOEErfM= + import-cwd@^2.0.0: version "2.1.0" resolved "https://registry.yarnpkg.com/import-cwd/-/import-cwd-2.1.0.tgz#aa6cf36e722761285cb371ec6519f53e2435b0a9" @@ -11033,6 +11048,16 @@ tough-cookie@~2.5.0: psl "^1.1.28" punycode "^2.1.1" +transit-immutable-js@^0.7.0: + version "0.7.0" + resolved "https://registry.yarnpkg.com/transit-immutable-js/-/transit-immutable-js-0.7.0.tgz#993e25089b6311ff402140f556276d6d253005d9" + integrity sha1-mT4lCJtjEf9AIUD1VidtbSUwBdk= + +transit-js@^0.8.861: + version "0.8.861" + resolved "https://registry.yarnpkg.com/transit-js/-/transit-js-0.8.861.tgz#829e516b80349a41fff5d59f5e6993b5473f72c9" + integrity sha512-4O9OrYPZw6C0M5gMTvaeOp+xYz6EF79JsyxIvqXHlt+pisSrioJWFOE80N8aCPoJLcNaXF442RZrVtdmd4wkDQ== + tree-kill@1.2.2: version "1.2.2" resolved "https://registry.yarnpkg.com/tree-kill/-/tree-kill-1.2.2.tgz#4ca09a9092c88b73a7cdc5e8a01b507b0790a0cc" @@ -11443,7 +11468,7 @@ uuid@7.0.2: resolved "https://registry.yarnpkg.com/uuid/-/uuid-7.0.2.tgz#7ff5c203467e91f5e0d85cfcbaaf7d2ebbca9be6" integrity sha512-vy9V/+pKG+5ZTYKf+VcphF5Oc6EFiu3W8Nv3P3zIh0EqVI80ZxOzuPfe9EHjkFNvf8+xuTHVeei4Drydlx4zjw== -uuid@^3.0.0, uuid@^3.0.1, uuid@^3.3.2: +uuid@^3.0.0, uuid@^3.0.1, uuid@^3.3.2, uuid@^3.4.0: version "3.4.0" resolved "https://registry.yarnpkg.com/uuid/-/uuid-3.4.0.tgz#b23e4358afa8a202fe7a100af1f5f883f02007ee" integrity sha512-HjSDRw6gZE5JMggctHBcjVak08+KEVhSIiDzFnT9S9aegmp85S/bReBVTb4QTFaRNptJ9kuYaNhnbNEOkbKb/A==