You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Deprecate <ControllerName>:stateChange in favor of :stateChanged
Since the `:stateChange` event was added to `BaseController`, we have
added a guideline asking engineers to use past tense for all event
names. This commit updates BaseController to align with that guideline.
To achieve backward compatibility, we add a new event, `:stateChanged`,
rather than replacing the existing event. We deprecate `:stateChange` by
adding some custom ESLint rules.
Each controller needs a default representation in order to fully initialize itself when [receiving a partial representation of state](#accept-an-optional-partial-representation-of-state). A default representation of state is also useful when testing interactions with a controller's `*:stateChange` event.
67
+
Each controller needs a default representation in order to fully initialize itself when [receiving a partial representation of state](#accept-an-optional-partial-representation-of-state). A default representation of state is also useful when testing interactions with a controller's `*:stateChanged` event.
68
68
69
69
A function which returns this default representation should be defined and exported. It should be called `getDefault${ControllerName}State`.
70
70
@@ -226,7 +226,7 @@ const fooController = new FooController({
226
226
227
227
If the recipient controller uses a messenger, however, the callback pattern is unnecessary. Using the messenger not only aligns the controller with `BaseController`, but also reduces the number of options that consumers need to remember in order to use the controller:
228
228
229
-
✅ **The constructor subscribes to the `BarController:stateChange` event**
229
+
✅ **The constructor subscribes to the `BarController:stateChanged` event**
230
230
231
231
```typescript
232
232
/* === This repo: packages/foo-controller/src/FooController.ts === */
@@ -247,7 +247,7 @@ class FooController extends BaseController<
@@ -280,7 +280,7 @@ const fooControllerMessenger = new Messenger<
280
280
parent: rootMessenger,
281
281
});
282
282
rootMessenger.delegate({
283
-
events: ['BarController:stateChange'],
283
+
events: ['BarController:stateChanged'],
284
284
messenger: fooControllerMessenger,
285
285
});
286
286
const fooController =newFooController({
@@ -541,16 +541,16 @@ type FooControllerGetStateAction = ControllerGetStateAction<
541
541
>;
542
542
```
543
543
544
-
## Define the `*:stateChange` event using the `ControllerStateChangeEvent` utility type
544
+
## Define the `*:stateChanged` event using the `ControllerStateChangedEvent` utility type
545
545
546
-
Each controller needs a type for its `*:stateChange` event. The `ControllerStateChangeEvent` utility type from the `@metamask/base-controller` package should be used to define this type.
546
+
Each controller needs a type for its `*:stateChanged` event. The `ControllerStateChangedEvent` utility type from the `@metamask/base-controller` package should be used to define this type.
547
547
548
-
The name of this type should be `${ControllerName}StateChangeEvent`.
548
+
The name of this type should be `${ControllerName}StateChangedEvent`.
One way to fix this is to check if the other controller (the one being subscribed to) has a more suitable, granular event for the data being acted upon. For instance, `NetworkController` has a `networkDidChange` event which can be used in place of `NetworkController:stateChange` if the subscribing controller needs to know when the network has been switched:
1057
+
One way to fix this is to check if the other controller (the one being subscribed to) has a more suitable, granular event for the data being acted upon. For instance, `NetworkController` has a `networkDidChange` event which can be used in place of `NetworkController:stateChanged` if the subscribing controller needs to know when the network has been switched:
1058
1058
1059
-
✅ **`NetworkController:networkDidChange` is used instead of `NetworkController:stateChange`**
1059
+
✅ **`NetworkController:networkDidChange` is used instead of `NetworkController:stateChanged`**
0 commit comments