Skip to content

Commit 2eba67c

Browse files
committed
feat: convert select all module to container
1 parent 31355fe commit 2eba67c

File tree

1 file changed

+31
-31
lines changed

1 file changed

+31
-31
lines changed

packages/pluggableWidgets/datagrid-web/src/Datagrid.depsContainer.ts

Lines changed: 31 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import { useConst } from "@mendix/widget-plugin-mobx-kit/react/useConst";
1616
import { useSetup } from "@mendix/widget-plugin-mobx-kit/react/useSetup";
1717

1818
import { generateUUID } from "@mendix/widget-plugin-platform/framework/generate-uuid";
19-
import { Container, DependencyModule, injected, token } from "brandi";
19+
import { Container, injected, token } from "brandi";
2020
import { useEffect } from "react";
2121
import { DatagridContainerProps, SelectionCounterPositionEnum } from "../typings/DatagridProps";
2222
import { DatasourceParamsController } from "./controllers/DatasourceParamsController";
@@ -129,8 +129,6 @@ class RootContainer extends Container {
129129
constructor() {
130130
super();
131131
this.bind(TOKENS.setupService).toInstance(DatagridSetupService).inSingletonScope();
132-
this.bind(TOKENS.exportProgressService).toInstance(ProgressService).inSingletonScope();
133-
this.bind(TOKENS.selectAllProgressService).toInstance(ProgressService).inSingletonScope();
134132
}
135133
}
136134

@@ -140,15 +138,23 @@ class DatagridContainer extends Container {
140138
* Setup container bindings.
141139
* @remark Make sure not to bind things that already exist in root container.
142140
*/
143-
init(props: MainGateProps, root: RootContainer, selectAllModule: DependencyModule): DatagridContainer {
141+
init(props: MainGateProps, root: RootContainer, selectAllModule: Container): DatagridContainer {
144142
this.extend(root);
145143

144+
// Connect select all module
145+
const selectAllService = selectAllModule.get(TOKENS.selectAllService);
146+
const selectAllProgress = selectAllModule.get(TOKENS.selectAllProgressService);
147+
// Bind select all service
148+
this.bind(TOKENS.selectAllService).toConstant(selectAllService);
149+
// Bind select all progress
150+
this.bind(TOKENS.selectAllProgressService).toConstant(selectAllProgress);
151+
152+
// Create main gate
153+
this.bind(TOKENS.exportProgressService).toInstance(ProgressService).inSingletonScope();
146154
const exportProgress = this.get(TOKENS.exportProgressService);
147-
const selectAllProgress = this.get(TOKENS.selectAllProgressService);
148155
const gateProvider = new ClosableGateProvider<MainGateProps>(props, function isLocked() {
149156
return exportProgress.inProgress || selectAllProgress.inProgress;
150157
});
151-
152158
this.setProps = props => gateProvider.setProps(props);
153159

154160
// Bind main gate
@@ -185,9 +191,6 @@ class DatagridContainer extends Container {
185191
// Pagination service
186192
this.bind(TOKENS.paginationService).toInstance(PaginationController).inSingletonScope();
187193

188-
// Setup service
189-
this.bind(TOKENS.setupService).toInstance(DatagridSetupService).inSingletonScope();
190-
191194
// Events channel for child widgets
192195
this.bind(TOKENS.parentChannelName)
193196
.toInstance(() => `Datagrid@${generateUUID()}`)
@@ -247,9 +250,6 @@ class DatagridContainer extends Container {
247250
// Hydrate filters from props
248251
this.get(TOKENS.combinedFilter).hydrate(props.datasource.filter);
249252

250-
// Bind select all service
251-
this.use(TOKENS.selectAllService).from(selectAllModule);
252-
253253
return this;
254254
}
255255

@@ -260,20 +260,23 @@ class DatagridContainer extends Container {
260260

261261
type SelectAllGateProps = Pick<DatagridContainerProps, "itemSelection" | "datasource">;
262262

263-
/** Module used to bind independent query and gate for select all service */
264-
class SelectAllModule extends DependencyModule {
263+
/** Module used to create select all service with independent set of deps. */
264+
class SelectAllModule extends Container {
265265
id = `SelectAllModule@${generateUUID()}`;
266-
/** Method for bindings that depend on props. */
267266
init(props: SelectAllGateProps, root: RootContainer): SelectAllModule {
268-
const setupService = root.get(TOKENS.setupService);
269-
const progress = root.get(TOKENS.selectAllProgressService);
270-
const gateProvider = new GateProvider<SelectAllGateProps>(props);
271-
const query = new DatasourceService(setupService, gateProvider.gate);
272-
const selectService = new SelectAllService(setupService, gateProvider.gate, query, progress);
267+
this.extend(root);
273268

269+
const gateProvider = new GateProvider<SelectAllGateProps>(props);
274270
this.setProps = props => gateProvider.setProps(props);
271+
272+
// Bind service deps
273+
this.bind(TOKENS.selectAllGate).toConstant(gateProvider.gate);
274+
this.bind(TOKENS.queryGate).toConstant(gateProvider.gate);
275+
this.bind(TOKENS.query).toInstance(DatasourceService).inSingletonScope();
276+
this.bind(TOKENS.selectAllProgressService).toInstance(ProgressService).inSingletonScope();
277+
275278
// Finally bind select all service
276-
this.bind(TOKENS.selectAllService).toConstant(selectService);
279+
this.bind(TOKENS.selectAllService).toInstance(SelectAllService).inSingletonScope();
277280

278281
return this;
279282
}
@@ -284,16 +287,13 @@ class SelectAllModule extends DependencyModule {
284287
}
285288

286289
export function useDatagridDepsContainer(props: DatagridContainerProps): Container {
287-
const [container, selectAllModule] = useConst(
288-
/** Function to create main container and setup prop dependant bindings. */
289-
function init(): [DatagridContainer, SelectAllModule] {
290-
const root = new RootContainer();
291-
const selectAllModule = new SelectAllModule().init(props, root);
292-
const container = new DatagridContainer().init(props, root, selectAllModule);
293-
294-
return [container, selectAllModule];
295-
}
296-
);
290+
const [container, selectAllModule] = useConst(function init(): [DatagridContainer, SelectAllModule] {
291+
const root = new RootContainer();
292+
const selectAllModule = new SelectAllModule().init(props, root);
293+
const container = new DatagridContainer().init(props, root, selectAllModule);
294+
295+
return [container, selectAllModule];
296+
});
297297

298298
// Run setup hooks on mount
299299
useSetup(() => container.get(TOKENS.setupService));

0 commit comments

Comments
 (0)