From 2c2df2d58780438927f83f0f51e1bc3f2c83d1ad Mon Sep 17 00:00:00 2001 From: dineug Date: Sun, 28 Jan 2024 01:52:54 +0900 Subject: [PATCH] fix: hook reference bug --- packages/erd-editor/package.json | 2 +- .../src/engine/modules/relationship/hooks.ts | 6 ++++-- .../src/engine/modules/table-column/hooks.ts | 21 +++++++++++-------- packages/erd-editor/src/index.dev.ts | 10 ++++++++- 4 files changed, 26 insertions(+), 13 deletions(-) diff --git a/packages/erd-editor/package.json b/packages/erd-editor/package.json index 936123ac..5e63f232 100644 --- a/packages/erd-editor/package.json +++ b/packages/erd-editor/package.json @@ -1,6 +1,6 @@ { "name": "@dineug/erd-editor", - "version": "3.1.5", + "version": "3.1.6", "description": "Entity-Relationship Diagram Editor", "type": "module", "main": "./dist/erd-editor.js", diff --git a/packages/erd-editor/src/engine/modules/relationship/hooks.ts b/packages/erd-editor/src/engine/modules/relationship/hooks.ts index 79c281fc..66be464b 100644 --- a/packages/erd-editor/src/engine/modules/relationship/hooks.ts +++ b/packages/erd-editor/src/engine/modules/relationship/hooks.ts @@ -30,10 +30,11 @@ import { import { bHas } from '@/utils/bit'; import { relationshipSort } from '@/utils/draw-relationship/sort'; -const identificationHook: CO = function* (channel, { doc, collections }) { +const identificationHook: CO = function* (channel, state) { yield throttle( channel, function* () { + const { doc, collections } = state; const collection = query(collections).collection('relationshipEntities'); const relationships = collection.selectByIds(doc.relationshipIds); @@ -68,10 +69,11 @@ const identificationHook: CO = function* (channel, { doc, collections }) { ); }; -const startRelationshipHook: CO = function* (channel, { doc, collections }) { +const startRelationshipHook: CO = function* (channel, state) { yield throttle( channel, function* () { + const { doc, collections } = state; const collection = query(collections).collection('relationshipEntities'); const relationships = collection.selectByIds(doc.relationshipIds); diff --git a/packages/erd-editor/src/engine/modules/table-column/hooks.ts b/packages/erd-editor/src/engine/modules/table-column/hooks.ts index b8daaf85..e96b7552 100644 --- a/packages/erd-editor/src/engine/modules/table-column/hooks.ts +++ b/packages/erd-editor/src/engine/modules/table-column/hooks.ts @@ -10,12 +10,13 @@ import { import { changeColumnPrimaryKeyAction } from '@/engine/modules/table-column/atom.actions'; import { bHas } from '@/utils/bit'; -const changeColumnNotNullHook: CO = function* (channel, { collections }) { +const changeColumnNotNullHook: CO = function* (channel, state) { yield takeEvery( channel, function* ({ payload: { id }, }: ReturnType) { + const { collections } = state; const collection = query(collections).collection('tableColumnEntities'); const column = collection.selectById(id); if (!column) return; @@ -33,15 +34,16 @@ const changeColumnNotNullHook: CO = function* (channel, { collections }) { ); }; -const addColumnForeignKeyHook: CO = function* ( - channel, - { doc: { relationshipIds }, collections } -) { +const addColumnForeignKeyHook: CO = function* (channel, state) { yield takeEvery( channel, function* ({ payload: { id, end }, }: ReturnType) { + const { + doc: { relationshipIds }, + collections, + } = state; if (!relationshipIds.includes(id)) return; query(collections) @@ -53,15 +55,16 @@ const addColumnForeignKeyHook: CO = function* ( ); }; -const removeColumnForeignKeyHook: CO = function* ( - channel, - { doc: { relationshipIds }, collections } -) { +const removeColumnForeignKeyHook: CO = function* (channel, state) { yield takeEvery( channel, function* ({ payload: { id }, }: ReturnType) { + const { + doc: { relationshipIds }, + collections, + } = state; if (relationshipIds.includes(id)) return; const relationship = query(collections) diff --git a/packages/erd-editor/src/index.dev.ts b/packages/erd-editor/src/index.dev.ts index 9b32330a..f6b4f5ea 100644 --- a/packages/erd-editor/src/index.dev.ts +++ b/packages/erd-editor/src/index.dev.ts @@ -36,4 +36,12 @@ setGetShikiServiceCallback(getShikiService); // cssUnwrap(); hmr(); runStats(); -runEditor(); + +const editor1 = runEditor(); +const editor2 = runEditor(); + +const sharedStore1 = editor1.getSharedStore(); +const sharedStore2 = editor2.getSharedStore(); + +sharedStore1.subscribe(actions => sharedStore2.dispatch(actions)); +sharedStore2.subscribe(actions => sharedStore1.dispatch(actions));