Skip to content

Commit

Permalink
chore: migrate HID effects to effector-queue
Browse files Browse the repository at this point in the history
  • Loading branch information
mishamyrt committed Mar 10, 2024
1 parent 1668a5e commit fc34a7c
Show file tree
Hide file tree
Showing 10 changed files with 51 additions and 103 deletions.
1 change: 1 addition & 0 deletions frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
"colorjs.io": "0.5.0",
"deep-equal": "2.2.3",
"effector": "23.2.0",
"effector-queue": "1.0.2",
"patronum": "2.2.0",
"svelte-awesome-color-picker": "2.4.8"
}
Expand Down
2 changes: 1 addition & 1 deletion frontend/package.json.md5
Original file line number Diff line number Diff line change
@@ -1 +1 @@
8116f2f1fa673af023647151fc26e960
7874e274a99b328242098e3f01e1d9d1
11 changes: 11 additions & 0 deletions frontend/pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 12 additions & 6 deletions frontend/src/entities/device/model/store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,18 @@ export const firmwareVersionStore = createStore('dev', {

export const getFirmwareFx = createEffect('getFirmware', { handler: getFirmware })
export const getSupportsFx = createEffect('getSupports', { handler: getSupports })
export const saveStateFx = createHIDEffect('saveState', saveState)
export const restoreUserStateFx = createHIDEffect('restoreUserStateFx', restoreState)
export const restoreDefaultStateFx = createHIDEffect(
'restoreDefaultState',
restoreDefaultState
)
export const saveStateFx = createHIDEffect({
name: 'saveStateFx',
handler: saveState
})
export const restoreUserStateFx = createHIDEffect({
name: 'restoreUserStateFx',
handler: restoreState
})
export const restoreDefaultStateFx = createHIDEffect({
name: 'restoreDefaultStateFx',
handler: restoreDefaultState
})

sample({
clock: getFirmwareFx.doneData,
Expand Down
5 changes: 4 additions & 1 deletion frontend/src/entities/keys/model/stores/keymap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,10 @@ export const secondaryActionStore = combine(keyMapStore, selectedKeyStore, (keyM
})
export const hasSecondaryActionStore = not(empty(secondaryActionStore))

const getKeysFx = createHIDEffect('getKeys', getKeys)
const getKeysFx = createHIDEffect({
name: 'getKeysFx',
handler: getKeys
})
const setKeysFx = createEffect('setKeys', { handler: setKeys })

// Report that supported device is connected
Expand Down
5 changes: 4 additions & 1 deletion frontend/src/entities/keys/model/stores/static.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,10 @@ export const keyGroupsStore = createStore<KeyGroup[]>([], { name: 'keyGroups' })
export const keyNamesStore = createStore<KeyNames>({}, { name: 'keyNames' })

const getGroupsFx = createEffect('getGroupsFx', { handler: getGroups })
const getDefaultKeysFx = createHIDEffect('getDefaultKeysFx', getDefaultKeys)
const getDefaultKeysFx = createHIDEffect({
name: 'getDefaultKeysFx',
handler: getDefaultKeys
})

sample({
clock: keysInitiated,
Expand Down
20 changes: 16 additions & 4 deletions frontend/src/entities/lights/model/store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,22 @@ const { tick } = interval({

// HID effects
// This effect is using for connection check
export const getStateFx = createHIDEffect('getState', getLightState)
export const setStateFx = createHIDEffect('setState', setLightState)
export const setBacklightColorFx = createHIDEffect('setBacklightColorFx', setBacklightColor)
export const getBacklightColorsFx = createHIDEffect('getBacklightColors', getBacklightColors)
export const getStateFx = createHIDEffect({
name: 'getStateFx',
handler: getLightState
})
export const setStateFx = createHIDEffect({
name: 'setStateFx',
handler: setLightState
})
export const setBacklightColorFx = createHIDEffect({
name: 'setBacklightColorFx',
handler: setBacklightColor
})
export const getBacklightColorsFx = createHIDEffect({
name: 'getBacklightColorsFx',
handler: getBacklightColors
})
// Simple effects
export const getModesFx = createEffect(getModes)

Expand Down
1 change: 0 additions & 1 deletion frontend/src/shared/lib/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
export * from './from-wails-event'
export * from './sequential-effect'
export * from './strings'
87 changes: 0 additions & 87 deletions frontend/src/shared/lib/sequential-effect.ts

This file was deleted.

4 changes: 2 additions & 2 deletions frontend/src/shared/model/hid-effects.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { createSequence } from '$shared/lib'
import { createQueue } from 'effector-queue'

const [createHIDEffect, pendingHIDStore] = createSequence({
const [createHIDEffect, pendingHIDStore] = createQueue({
minInterval: 200
})

Expand Down

0 comments on commit fc34a7c

Please sign in to comment.