Skip to content

Commit

Permalink
fix(preferences): return type
Browse files Browse the repository at this point in the history
Use `connect` and call the function directly
  • Loading branch information
unional committed Oct 27, 2022
1 parent cf41bf8 commit edca7c1
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 30 deletions.
5 changes: 5 additions & 0 deletions .changeset/poor-squids-clean.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@just-web/preferences": patch
---

Fix `app.preference.*` return types
42 changes: 12 additions & 30 deletions plugins/preferences/ts/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { command, CommandsContext } from '@just-web/commands'
import { LogContext } from '@just-web/log'
import { KeyboardContext } from '@just-web/keyboard'
import { definePlugin } from '@just-web/types'

/**
Expand All @@ -21,38 +21,20 @@ export const clearUserPreferences = command('just-web.clearUserPreferences')

const plugin = definePlugin(() => ({
name: '@just-web/preferences',
init: ({ commands }: LogContext & CommandsContext) => {
commands.contributions.add(clearUserPreferences)
init: (ctx: CommandsContext & Partial<KeyboardContext>) => {
getUserPreference.connect(ctx)
setUserPreference.connect(ctx)
updateUserPreference.connect(ctx)
clearUserPreference.connect(ctx)
clearUserPreferences.connect(ctx)

return [{
preferences: {
get(key: string) {
return commands.handlers.invoke(
getUserPreference.id,
...getUserPreference.defineArgs(key)
)
},
set(key: string, value: string) {
return commands.handlers.invoke(
setUserPreference.id,
...setUserPreference.defineArgs(key, value)
)
},
update(key: string, handler: (value: string | undefined) => string) {
return commands.handlers.invoke(
updateUserPreference.id,
...updateUserPreference.defineArgs(key, handler)
)
},
clear(key: string) {
return commands.handlers.invoke(
clearUserPreference.id,
...clearUserPreference.defineArgs(key)
)
},
clearAll() {
return commands.handlers.invoke(clearUserPreferences.id)
}
get: getUserPreference,
set: setUserPreference,
update: updateUserPreference,
clear: clearUserPreference,
clearAll: clearUserPreferences
}
}]
}
Expand Down

0 comments on commit edca7c1

Please sign in to comment.