From c98657b8303150bfda3bdea750055b83a29b27a3 Mon Sep 17 00:00:00 2001 From: GeoSot Date: Thu, 3 Jun 2021 18:53:27 +0300 Subject: Add `getOrCreateInstance` method in base-component (#33276) Co-authored-by: Rohit Sharma Co-authored-by: XhmikosR --- js/src/base-component.js | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'js/src/base-component.js') diff --git a/js/src/base-component.js b/js/src/base-component.js index 368cc99c8..cadd53d26 100644 --- a/js/src/base-component.js +++ b/js/src/base-component.js @@ -51,6 +51,10 @@ class BaseComponent { return Data.get(element, this.DATA_KEY) } + static getOrCreateInstance(element, config = {}) { + return this.getInstance(element) || new this(element, typeof config === 'object' ? config : null) + } + static get VERSION() { return VERSION } -- cgit v1.2.3