Skip to content

Commit

Permalink
Dispatch StateEffect when new data is loaded
Browse files Browse the repository at this point in the history
  • Loading branch information
jesperengstrom committed Dec 12, 2024
1 parent 213ef72 commit e840722
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
12 changes: 11 additions & 1 deletion packages/supersearch/src/lib/components/SuperSearch.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import { onMount, onDestroy, type Snippet } from 'svelte';
import CodeMirror, { type ChangeCodeMirrorEvent } from '$lib/components/CodeMirror.svelte';
import { EditorView, placeholder as placeholderExtension, keymap } from '@codemirror/view';
import { Compartment, type Extension } from '@codemirror/state';
import { Compartment, StateEffect, type Extension } from '@codemirror/state';
import { type LanguageSupport } from '@codemirror/language';
import submitFormOnEnterKey from '$lib/extensions/submitFormOnEnterKey.js';
import preventNewLine from '$lib/extensions/preventNewLine.js';
Expand Down Expand Up @@ -63,6 +63,16 @@
}
});
const onDataUpdateEffect = StateEffect.define<{ message: string }>({});
$effect(() => {
if (search.data) {
const effects = { effects: onDataUpdateEffect.of({ message: 'new_data' }) };
expandedEditorView?.dispatch(effects);
collapsedEditorView?.dispatch(effects);
}
});
const extensionsWithDefaults = [
keymap.of(standardKeymap), // Needed for atomic ranges to work. Maybe we can use a subset?
submitFormOnEnterKey(form),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,14 @@ function lxlQualifierPlugin(getLabelFn?: GetLabelFunction) {
update(update: ViewUpdate) {
if (update.docChanged || syntaxTree(update.startState) != syntaxTree(update.state)) {
this.qualifiers = getQualifiers(update.view);
} else {
for (const tr of update.transactions) {
for (const e of tr.effects) {
if (e.value.message === 'new_data') {
this.qualifiers = getQualifiers(update.view);
}
}
}
}
}
},
Expand Down

0 comments on commit e840722

Please sign in to comment.