Wikibase
MediaWiki Wikibase extension
|
accepted
The Wikidata Bridge app uses VueJs version 2 and Vuex version 3 for state management. Both within the store and in vue components the calls to dispatch()
and commit()
are not type safe. That means that they accept any arguments and TypeScript will still compile without error. Since dispatch()
and commit()
are typical seams that are usually mocked during unit testing, it is up to integration, end-to-end and browser tests to detect these errors.
This is particularly unfortunate as the store is one of the central locations where business logic happens.
We considered two options:
dispatch()
and commit()
to get type safetyThe advantages of doing it ourselves included us not having another dependency. The risks include that this would be yet another homebrew layer of abstraction.
The advantages of using vuex-smart-modules include:
BRIDGE_SET_TARGET_VALUE
constants without having to fall back to string literalsgo to method definition
functionalityPromise<any>
being used everywherevuex-class
dependency as we can use vuex-smart-modules for all store access in componentsThe risks include:
We decided to rewrite our Vuex store using vuex-smart-modules version 0.3.4
dispatch()
and commit()
in the store will be type safethis.dispatch()
which returns Promise<any>
and use our actions directly and thus fully benefit from their return types.Module
constructor of vuex-smart-modules consumes the class definitions of, for example, RootActions
themselves. Therefore, it is not possible to use the RootActions
constructor for dependency injection// @ts-ignore
Future learnings should be amended here