Skip to content

Commit 9868768

Browse files
fengmk2SEWeiTung
andauthored
feat: add getSingletonInstance alias to singleton.get(id) (#5216)
Co-authored-by: William.Tung <[email protected]>
1 parent 768affa commit 9868768

File tree

2 files changed

+9
-0
lines changed

2 files changed

+9
-0
lines changed

lib/core/singleton.js

+5
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,11 @@ class Singleton {
7979
return this.clients.get(id);
8080
}
8181

82+
// alias to `get(id)`
83+
getSingletonInstance(id) {
84+
return this.clients.get(id);
85+
}
86+
8287
createInstance(config, clientName) {
8388
// async creator only support createInstanceAsync
8489
assert(!is.asyncFunction(this.create),

test/lib/core/singleton.test.js

+4
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,11 @@ describe('test/lib/core/singleton.test.js', () => {
115115
singleton.init();
116116
assert(app.dataService instanceof Singleton);
117117
assert(app.dataService.get('first').config.foo === 'bar1');
118+
assert(app.dataService.getSingletonInstance('first').config.foo === 'bar1');
119+
assert(app.dataService.get('first'), app.dataService.getSingletonInstance('first'));
118120
assert(app.dataService.get('second').config.foo === 'bar');
121+
assert(app.dataService.getSingletonInstance('second').config.foo === 'bar');
122+
assert(app.dataService.get('second'), app.dataService.getSingletonInstance('second'));
119123
assert(typeof app.dataService.createInstance === 'function');
120124
});
121125

0 commit comments

Comments
 (0)