Skip to content

Commit

Permalink
fix: hook reference bug
Browse files Browse the repository at this point in the history
  • Loading branch information
dineug committed Jan 27, 2024
1 parent 3219285 commit 2c2df2d
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 13 deletions.
2 changes: 1 addition & 1 deletion packages/erd-editor/package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
6 changes: 4 additions & 2 deletions packages/erd-editor/src/engine/modules/relationship/hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -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);

Expand Down
21 changes: 12 additions & 9 deletions packages/erd-editor/src/engine/modules/table-column/hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<typeof changeColumnPrimaryKeyAction>) {
const { collections } = state;
const collection = query(collections).collection('tableColumnEntities');
const column = collection.selectById(id);
if (!column) return;
Expand All @@ -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<typeof addRelationshipAction>) {
const {
doc: { relationshipIds },
collections,
} = state;
if (!relationshipIds.includes(id)) return;

query(collections)
Expand All @@ -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<typeof removeRelationshipAction>) {
const {
doc: { relationshipIds },
collections,
} = state;
if (relationshipIds.includes(id)) return;

const relationship = query(collections)
Expand Down
10 changes: 9 additions & 1 deletion packages/erd-editor/src/index.dev.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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));

0 comments on commit 2c2df2d

Please sign in to comment.