Skip to content
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

[composable-controller] perf: Optimize expensive reduce operations, fix metadata instantiation #4968

Merged
Changes from 1 commit
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
2a4a115
perf: Convert reduce operations to re-use output object instead of cr…
MajorLift Nov 25, 2024
2612d4a
fix: incorrect logic for assigning fall-back metadata properties for …
MajorLift Nov 25, 2024
87fc3f6
fix: type issue with assigning property to generic type
MajorLift Nov 25, 2024
2a18840
feat: **BREAKING:** Re-define `controllers` constructor option from a…
MajorLift Nov 25, 2024
7b0be9f
fix: Check that input is V1/V2 controller when instantiating Composab…
MajorLift Nov 25, 2024
871486a
test: Update tests
MajorLift Nov 25, 2024
c103016
Update changelogs
MajorLift Nov 25, 2024
c570e26
Update comments
MajorLift Nov 25, 2024
901e8b4
perf: Replace` Object.assign` with property assignments
MajorLift Nov 25, 2024
55af3a6
Assign metadata to each child controller instead of to individual nes…
MajorLift Nov 25, 2024
c533f7c
Remove non-controller properties from state, metadata fields
MajorLift Nov 25, 2024
c1a4670
test: fix missing `stateChange` events in test composable-controller …
MajorLift Nov 25, 2024
5b94171
Update jsdoc comments
MajorLift Nov 25, 2024
571a483
Fix undefined property deletion behavior
MajorLift Nov 25, 2024
77fb0e8
Apply `eslint-disable` to entire test file to allow PascalCase contro…
MajorLift Nov 25, 2024
a7e7296
Fix types
MajorLift Nov 26, 2024
b23ef8e
Update changelog
MajorLift Nov 26, 2024
c420da0
Wrap delete operations for non-controllers in try-catch block
MajorLift Dec 3, 2024
518eaa7
Add tests for `stateChange` events that are not defined or omitted fr…
MajorLift Dec 3, 2024
244f6c8
Update packages/composable-controller/CHANGELOG.md
MajorLift Dec 3, 2024
0b52f5f
Add links to changelog entries
MajorLift Dec 3, 2024
61c9697
Add comments explaining reduce implementation and type assertions
MajorLift Dec 3, 2024
74e45f4
Rename `QuxController` to `ControllerWithoutStateChangeEvent`
MajorLift Dec 3, 2024
db8147a
Rename `ChildControllers` type parameter to `ChildControllersMap`
MajorLift Dec 3, 2024
4583266
Merge branch 'main' into jongsun/perf/composable-controller/241124-re…
MajorLift Dec 4, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Rename QuxController to ControllerWithoutStateChangeEvent
  • Loading branch information
MajorLift committed Dec 3, 2024
commit 74e45f49eedcc37f62f6eb368501a6d5e6f6d2dd
47 changes: 26 additions & 21 deletions packages/composable-controller/src/ComposableController.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -168,40 +168,40 @@ class BazController extends BaseControllerV1<never, BazControllerState> {
}
}

type QuxControllerState = {
type ControllerWithoutStateChangeEventState = {
qux: string;
};

type QuxMessenger = RestrictedControllerMessenger<
'QuxController',
never,
type ControllerWithoutStateChangeEventMessenger = RestrictedControllerMessenger<
'ControllerWithoutStateChangeEvent',
never,
QuzControllerEvent,
never,
QuzControllerEvent['type']
>;

const quxControllerStateMetadata = {
const controllerWithoutStateChangeEventStateMetadata = {
qux: {
persist: true,
anonymous: true,
},
};

class QuxController extends BaseController<
'QuxController',
QuxControllerState,
QuxMessenger
class ControllerWithoutStateChangeEvent extends BaseController<
'ControllerWithoutStateChangeEvent',
ControllerWithoutStateChangeEventState,
ControllerWithoutStateChangeEventMessenger
> {
constructor(messagingSystem: QuxMessenger) {
constructor(messagingSystem: ControllerWithoutStateChangeEventMessenger) {
super({
messenger: messagingSystem,
metadata: quxControllerStateMetadata,
name: 'QuxController',
metadata: controllerWithoutStateChangeEventStateMetadata,
name: 'ControllerWithoutStateChangeEvent',
state: { qux: 'qux' },
});
}

updateQux(qux: string) {
updateState(qux: string) {
super.update((state) => {
state.qux = qux;
});
Expand All @@ -213,7 +213,7 @@ type ControllersMap = {
QuzController: QuzController;
BarController: BarController;
BazController: BazController;
QuxController: QuzController;
ControllerWithoutStateChangeEvent: ControllerWithoutStateChangeEvent;
};

describe('ComposableController', () => {
Expand Down Expand Up @@ -621,12 +621,16 @@ describe('ComposableController', () => {
never,
FooControllerEvent
>();
const quxControllerMessenger = controllerMessenger.getRestricted({
name: 'QuxController',
allowedActions: [],
allowedEvents: [],
});
const quxController = new QuxController(quxControllerMessenger);
const controllerWithoutStateChangeEventMessenger =
controllerMessenger.getRestricted({
name: 'ControllerWithoutStateChangeEvent',
allowedActions: [],
allowedEvents: [],
});
const controllerWithoutStateChangeEvent =
new ControllerWithoutStateChangeEvent(
controllerWithoutStateChangeEventMessenger,
);
const fooControllerMessenger = controllerMessenger.getRestricted({
name: 'FooController',
allowedActions: [],
Expand All @@ -637,7 +641,8 @@ describe('ComposableController', () => {
() =>
new ComposableController({
controllers: {
QuxController: quxController,
ControllerWithoutStateChangeEvent:
controllerWithoutStateChangeEvent,
FooController: fooController,
},
messenger: controllerMessenger.getRestricted({
Expand Down
Loading