From 457b07863b5a2419592ff9a643fe413e3dfc4ae6 Mon Sep 17 00:00:00 2001 From: Vladimir Vershinin Date: Wed, 30 Oct 2019 21:24:31 +0300 Subject: [PATCH] Control idents also for getInstance method, clear idents in unsetInstance #244 --- src/mixin/ident-map.js | 32 ++++++++++++++++++++++++++++---- test/app.vue | 40 ++++++++++++++++++++++++++-------------- 2 files changed, 54 insertions(+), 18 deletions(-) diff --git a/src/mixin/ident-map.js b/src/mixin/ident-map.js index a864d89b..7ef1e1a5 100644 --- a/src/mixin/ident-map.js +++ b/src/mixin/ident-map.js @@ -68,17 +68,18 @@ export default { */ instanceFactoryCall (ident, factory) { if (ident && this.$identityMap.has(ident, INSTANCES_POOL)) { + this.idents[ident] = true return this.$identityMap.get(ident, INSTANCES_POOL) } - const val = factory() + const inst = factory() if (ident) { this.idents[ident] = true - this.$identityMap.set(ident, val, INSTANCES_POOL) + this.$identityMap.set(ident, inst, INSTANCES_POOL) } - return val + return inst }, /** * @param {string|undefined} ident @@ -87,14 +88,37 @@ export default { getInstance (ident) { if (!ident) return + if (!this.hasInstance(ident)) return + + this.idents[ident] = true + return this.$identityMap.get(ident, INSTANCES_POOL) }, + /** + * @param {string|undefined} ident + * @returns {*} + */ + hasInstance (ident) { + if (!ident) return false + + return this.$identityMap.has(ident, INSTANCES_POOL) + }, + /** + * @param {string|undefined} ident + */ + unsetInstance (ident) { + if (!ident) return + + delete this.idents[ident] + + this.$identityMap.unset(ident, INSTANCES_POOL) + }, /** * Unsets all self indets * @return {void} */ unsetInstances () { - keys(this.idents).forEach(ident => this.$identityMap.unset(ident, INSTANCES_POOL)) + keys(this.idents).forEach(::this.unsetInstance) }, }, } diff --git a/test/app.vue b/test/app.vue index bbe9859f..477a4f58 100644 --- a/test/app.vue +++ b/test/app.vue @@ -32,13 +32,13 @@ - - - - - - - + + + + + + + @@ -46,18 +46,26 @@ - +