Skip to content

Commit 81a9137

Browse files
author
Sean Warren
committed
feat: working version
2 parents b7cef5b + 5cb62be commit 81a9137

File tree

2 files changed

+24
-9
lines changed

2 files changed

+24
-9
lines changed

src/context/registry.js

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -57,17 +57,18 @@ export const extendAndPatchRegistry = (
5757
if (providerCls[clsName]) {
5858
providerCls[clsName] = cls;
5959
}
60+
const providerDefaultSettings = defaultSettings[providerCls.name];
61+
if (providerDefaultSettings) {
62+
Object.entries(providerDefaultSettings).forEach(([key, value]) => {
63+
if (providerCls[key]) {
64+
providerCls[key] = value;
65+
}
66+
});
67+
}
6068
});
61-
// Override defaults for this particular context provider
62-
const providerSpecificDefaults = defaultSettings[name] || {};
63-
64-
const combinedConfig = {
65-
...config,
66-
...providerSpecificDefaults,
67-
};
6869

6970
registryContainer.addProvider({
70-
instance: providerCls.getConstructorConfig(combinedConfig),
71+
instance: providerCls.getConstructorConfig(config),
7172
name,
7273
});
7374
});

tests/context.tests.ts

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ class ProviderEntity extends MaterialContextMixin(ApplicationContextMixin(Contex
3636
static Material = MockMaterial;
3737

3838
static Application = MockApplication;
39+
40+
static setting = 10;
3941
}
4042

4143
class DerivedProviderEntity extends ProviderEntity {
@@ -76,12 +78,24 @@ describe("ContextProviderRegistryContainer", () => {
7678
},
7779
};
7880

81+
const defaultSettings = {
82+
ProviderEntity: {
83+
setting: 100,
84+
},
85+
};
86+
7987
it("can be created and patched", () => {
80-
const registry = createAndPatchRegistry(classConfigObj, { Material: SpecificMockMaterial });
88+
const registry = createAndPatchRegistry(
89+
classConfigObj,
90+
{ Material: SpecificMockMaterial },
91+
defaultSettings,
92+
);
93+
8194
const _dataProvider = registry.findProviderInstanceByName("DataManager");
8295
const dataProvider = new _dataProvider.constructor(_dataProvider.config);
8396
const _appProvider = registry.findProviderInstanceByName("ApplicationDataManager");
8497
const appProvider = new _appProvider.constructor(_appProvider.config);
98+
expect(_dataProvider.constructor.setting).to.be.equal(100);
8599
expect(dataProvider.material).to.be.equal("defaultSpecificMockMaterial");
86100
expect(appProvider.application).to.be.equal("defaultSpecificMockApplication");
87101
});

0 commit comments

Comments
 (0)