-
-
Notifications
You must be signed in to change notification settings - Fork 133
feat(web): cleanup of variable stores 🎼 #15470
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
base: epic/web-core
Are you sure you want to change the base?
Conversation
User Test ResultsTest specification and instructions User tests are not required Test Artifacts
|
This addresses code review comments in #15437 and removes some unnecessary definitions related to variable stores. It keeps the `VariableStoreSerializer` interface although currently `VariableStoreCookieSerializer` is the only implementation. Conceptually IMO it makes sense to use a more abstract interface so that in the future for example we could easily use a different store for a node implementation. Details of this change: - remove `VariableStoreDictionary` interface and replace with `VariableStore` type - remove `VarStoreSerializer` class and replace with ` CookieSerializer<VariableStore>` Follow-up-of: #15437 Test-bot: skip
8fb8c95 to
01bee77
Compare
| * @returns an object with each property referencing a variable store | ||
| */ | ||
| get variableStores(): VariableStoreDictionary { | ||
| get variableStores(): VariableStore { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hmm, the function is plural but the return value is singular. Is that right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changed to plural.
| [name: string]: string; | ||
| }; | ||
|
|
||
| export type VariableStore = { [name: string]: string; }; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should probably be VariableStores since it is can contain more than one value.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See comment below (#15470 (comment)).
| loadStore(keyboardID: string, storeName: string): VariableStores; | ||
| saveStore(keyboardID: string, storeName: string, storeMap: VariableStores): void; | ||
| findStores(keyboardID: string): VariableStores[]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This doesn't make sense to me. loadStore should be returning 1 store. findStores shouldn't be finding an array of a set of variable stores!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's not as bad as it looks (other than that it looks bad and might be confusing): currently each VariableStores object contains only one key/value pair (except in tests), so loadStore and saveStore function names make sense. findStores returns all cookies/stores for a keyboard.
Thinking about it - maybe the term store is part of a problem. In every day life I think of a store as something where you can get different things. With that in mind, a VariableStore in our code would be able to hold multiple key/value pairs. The plural VariableStores would be several stores, each holding multiple key/value pairs.
But if we think from .kmn, store(x) defines a variable store, i.e. one key/value pair. This calls for naming the type that can hold multiple key/value pairs a VariableStores type.
Since currently we store only one key/value pair in that type although it can hold multiple ones, I think it's probably best to change it back to VariableStore and use it in the sense of a .kmn variable store.
I think if we implement what's discussed in #15436 (comment) things might get a bit cleaner. It doesn't help with the terminology, but at least then it would hold only one key/value pair and the type would match that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we only ever store one key + value in the object then why don't we change it to a more conventional pattern:
export type VariableStore = { name: string; value: string; }That also then allows us to add extra metadata in the future if we want and eliminates this confusion. IMHO the current model is fragile and liable to trip maintainers up in the future (as we can see in this discussion where we are going around in circles). I can't see that we are deriving any benefits from the current model, either in performance or in clarity.
Either that, or we refactor to store all of the variable stores in a single object... but that seems more complicated from my reading of the code.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(except in tests)
If tests are doing something different to the real-life use of the code, then the tests are definitely wrong -- tests must match the real-life usage or they are testing the wrong thing. IMVHO it's crazy that the only place this pattern is used is in the unit tests!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not entirely sure that my analysis was correct.
jsKeyboard.ts has this code: values[store] = this.scriptObject[store]; and I'm not sure what scriptObject[store] can return.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, that is certainly adding more than one value into the VariableStore type. From my current reading, it's buggy -- in one place we add multiple values to one VariableStore but in other places we have multiple VariableStores. I think we need to review again -- it's a very simple data model, but the implementation seems overly complicated right now.
b94661a to
01bee77
Compare
|
Reverted the rename from |
| @@ -54,6 +32,8 @@ export class VariableStoreCookieSerializer implements VariableStoreSerializer { | |||
| * @returns An array of VariableStore objects found for the keyboard. | |||
| */ | |||
| public findStores(keyboardID: string): VariableStore[] { | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the broken function, right? VariableStore is already a map, so it should be returning a map, not an array of maps. And this is a change in epic/web-core, not in the current alpha, so I think it's a change you made based on VariableStore being badly named.
Should we go ahead with naming it VariableStores and eliminate VariableStoreDictionary?
This addresses code review comments in #15437 and removes some unnecessary definitions related to variable stores. It keeps the
VariableStoreSerializerinterface although currentlyVariableStoreCookieSerializeris the only implementation. Conceptually IMO it makes sense to use a more abstract interface so that in the future for example we could easily use a different store for a node implementation.Details of this change:
VariableStoreDictionaryinterface and replace withVariableStoretypeVarStoreSerializerclass and replace withCookieSerializer<VariableStore>Follow-up-of: #15437
Test-bot: skip