-
Notifications
You must be signed in to change notification settings - Fork 5
Allow removal and adding for plugins in iconMenu #861
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
oeninghe-dataport
wants to merge
19
commits into
next
Choose a base branch
from
fix/668-iconMenu-plugin-removal
base: next
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 9 commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
e14ded9
feat(iconMenu): `menus` should be mutable
oeninghe-dataport 8f36876
test(snowbox): allow removal and live insertion of iconMenu plugins
oeninghe-dataport 4888d29
fix(filter): reset filter state on plugin removal
oeninghe-dataport 866b395
Merge branch 'next' into fix/668-iconMenu-plugin-removal
oeninghe-dataport d7e23ae
refactor(iconMenu): extract lib function watchArray
oeninghe-dataport b47d6cf
feat(iconMenu): allow adding and removal of plugins
oeninghe-dataport 28a8ef6
refactor(iconMenu): replace watcher with explicit mutations
oeninghe-dataport bb128d2
test(snowbox): adapt new iconMenu modification
oeninghe-dataport 1d136e7
refactor(iconMenu): replace open/focusOpen watcher with mutations
oeninghe-dataport fe13760
fix: remove unused watchArray lib function
oeninghe-dataport d2b0008
refactor(iconMenu): simplify store action calls
oeninghe-dataport ee8f935
docs(iconMenu): fix maturity
oeninghe-dataport 962aa61
docs(iconMenu): fix maturity
oeninghe-dataport 441b0be
docs(iconMenu): fix maturity
oeninghe-dataport 42c1204
docs(iconMenu): fix maturity
oeninghe-dataport b6d0d30
docs(iconMenu): fix maturity
oeninghe-dataport 7b57647
fix(iconMenu): use `toRaw`, better safe than sorry
oeninghe-dataport b44a099
Merge branch 'next' into fix/668-iconMenu-plugin-removal
oeninghe-dataport 7bbdec2
perf: reduce store calls when plugin is removed
oeninghe-dataport File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,69 @@ | ||
| import type { WatchOptions, WatchSource } from 'vue' | ||
|
|
||
| import { watch } from 'vue' | ||
|
|
||
| function getDifference<T>(items: T[], otherItems: T[]) { | ||
| const unmatchedItems = [...otherItems] | ||
| return items.filter((item) => { | ||
| const matchIndex = unmatchedItems.findIndex((otherItem) => | ||
| Object.is(item, otherItem) | ||
| ) | ||
| if (matchIndex === -1) { | ||
| return true | ||
| } | ||
| unmatchedItems.splice(matchIndex, 1) | ||
| return false | ||
| }) | ||
| } | ||
|
|
||
| /** | ||
| * Watches an array and invokes callbacks for every added and removed item. | ||
| * | ||
| * @param source - Reactive array source to watch | ||
| * @param onAdded - Callback invoked for every added item | ||
| * @param onRemoved - Callback invoked for every removed item | ||
| * @param options - Vue watch options | ||
| */ | ||
| export function watchArray<T>( | ||
| source: WatchSource<T[]>, | ||
| onAdded: (item: T) => void, | ||
| onRemoved: (item: T) => void, | ||
| options?: WatchOptions | ||
| ) { | ||
| return watch( | ||
| source, | ||
| (newItems, oldItems) => { | ||
| const previousItems = oldItems ?? [] | ||
| getDifference(newItems, previousItems).forEach((item) => { | ||
| onAdded(item) | ||
| }) | ||
| getDifference(previousItems, newItems).forEach((item) => { | ||
| onRemoved(item) | ||
| }) | ||
| }, | ||
| options | ||
| ) | ||
| } | ||
|
|
||
| if (import.meta.vitest) { | ||
| const { expect, test, vi } = import.meta.vitest | ||
| const { ref } = await import('vue') | ||
|
|
||
| test('calls the respective callback for each added and removed item', () => { | ||
| const items = ref([{ id: 1 }, { id: 2 }]) | ||
| const onAdded = vi.fn() | ||
| const onRemoved = vi.fn() | ||
|
|
||
| watchArray(items, onAdded, onRemoved, { flush: 'sync' }) | ||
|
|
||
| // eslint-disable-next-line @typescript-eslint/no-non-null-assertion | ||
| const retainedItem = items.value[1]! | ||
| const addedItem = { id: 3 } | ||
| items.value = [retainedItem, addedItem] | ||
|
|
||
| expect(onAdded).toHaveBeenCalledOnce() | ||
| expect(onAdded).toHaveBeenCalledWith(addedItem) | ||
| expect(onRemoved).toHaveBeenCalledOnce() | ||
| expect(onRemoved).toHaveBeenCalledWith({ id: 1 }) | ||
| }) | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.