Activities/Wallet Refactor
This commit is contained in:
+8
-4
@@ -58,11 +58,15 @@ class SomeClass {
|
||||
protected store: BaseStore;
|
||||
|
||||
constructor(
|
||||
//
|
||||
// Dependency Injection first
|
||||
dependencies: {
|
||||
blockchain: BaseBlockchain,
|
||||
store: BaseStore,
|
||||
}
|
||||
},
|
||||
// Then main (required) initialization params
|
||||
initParams,
|
||||
// Then optional params (if applicable).
|
||||
opts,
|
||||
) {
|
||||
this.blockchain = dependencies.blockchain;
|
||||
this.store = dependencies.store;
|
||||
@@ -74,8 +78,6 @@ class SomeClass {
|
||||
|
||||
When creating classes, create static `from(...)` (or `fromSpecificThing(...)`) methods.
|
||||
|
||||
*Semantically, think of "from" as meaning "instantiate from": This is more succinct than a `create` factory method which, if we have multiple ways of instantiation, can become verbose. E.g. `PrivateKey.fromWIF()` as opposed to `PrivateKey.createFromWIF()`. It also allows us to differentiate between actually "creating" something (e.g. a `Filesystem.createFile(...)`) versus "instantiating" a representation of a "thing".*
|
||||
|
||||
In Javascript, a `constructor` cannot be asynchronous and we want to ensure that we can `await` class instantiation to mitigate against stateful errors.
|
||||
|
||||
For example:
|
||||
@@ -99,6 +101,8 @@ class SomeClass {
|
||||
|
||||
Although this isn't always necessary (i.e. not all instantiations need to be `async`), it keeps instantiation of classes consistent.
|
||||
|
||||
*Semantically, think of "from" as meaning "instantiate from": This is more succinct than a `createFrom...` factory method which, if we have multiple ways of instantiation, can become verbose. E.g. `PrivateKey.fromWIF()` as opposed to `PrivateKey.createFromWIF()`. It also allows us to differentiate between actually "creating" something (e.g. a `Filesystem.createFile(...)`) versus "instantiating" a representation of a "thing".*
|
||||
|
||||
### Validations
|
||||
|
||||
Check types with TypeScript - Runtime type-checking is a code smell. If the function accepts a string, assume it's been given a string. TypeScript definitions should expose improperly called functions to the developer at compile time, don't re-implement it at runtime.
|
||||
|
||||
Reference in New Issue
Block a user