Holy refactor, Batman: full layer support (MO/DF)
Wow, what a trip this was. Layer support is now fully implemented. Other changes here mostly revolve around the event dispatching model: more floating state (hidden in clases wherever) has been purged, with the reducer (now mutable, comments inline) serving, as it should, as the sole source of truth. Thunk support has been added to our fake Redux clone, allowing Action Creators to handle sequences of events (which is arguably a cleaner way of handling matrix changes when not all matrix changes should result in a new HID report - in the case of internal keys). A whole class has been deprecated (Keymap) which only served as another arbitor of state: instead, the MatrixScanner has been made smarter and handles diffing internally, dispatching an Action when needed (and allowing the reducer to parse the keymap and figure out what key is pressed - this is the infinitely cleaner solution when layers come into play).
This commit is contained in:
@@ -2,7 +2,6 @@ import logging
|
||||
|
||||
from kmk.common.event_defs import init_firmware
|
||||
from kmk.common.internal_state import ReduxStore, kmk_reducer
|
||||
from kmk.common.keymap import Keymap
|
||||
|
||||
try:
|
||||
from kmk.circuitpython.matrix import MatrixScanner
|
||||
@@ -40,9 +39,6 @@ class Firmware:
|
||||
))
|
||||
|
||||
def _subscription(self, state, action):
|
||||
if self.cached_state is None or self.cached_state.keymap != state.keymap:
|
||||
self.keymap = Keymap(state.keymap)
|
||||
|
||||
if self.cached_state is None or any(
|
||||
getattr(self.cached_state, k) != getattr(state, k)
|
||||
for k in state.__dict__.keys()
|
||||
@@ -55,4 +51,8 @@ class Firmware:
|
||||
|
||||
def go(self):
|
||||
while True:
|
||||
self.keymap.parse(self.matrix.raw_scan(), store=self.store)
|
||||
state = self.store.get_state()
|
||||
update = self.matrix.scan_for_changes(state.matrix)
|
||||
|
||||
if update:
|
||||
self.store.dispatch(update)
|
||||
|
Reference in New Issue
Block a user