From cba8b37551c591545539935ced4a9dccba14dc4a Mon Sep 17 00:00:00 2001 From: Vasil Vanchuk Date: Tue, 1 Sep 2015 18:40:50 +0300 Subject: [PATCH] Add check if component already registered --- addon/action-link.js | 27 +++++++++++--------- package.json | 7 ++--- tests/dummy/app/initializers/hightlightjs.js | 6 +++-- 3 files changed, 23 insertions(+), 17 deletions(-) diff --git a/addon/action-link.js b/addon/action-link.js index 1d3f190..3b0a357 100644 --- a/addon/action-link.js +++ b/addon/action-link.js @@ -2,6 +2,7 @@ import Em from 'ember'; import WithConfigMixin from 'ember-idx-utils/mixin/with-config'; import Modal from 'ember-idx-modal/modal'; var computed = Em.computed; +var COMPONENT_NAME = 'view:em-wysiwyg-action-link-modal'; export default Em.Component.extend(WithConfigMixin, { tagName: 'a', @@ -9,18 +10,20 @@ export default Em.Component.extend(WithConfigMixin, { linkHref: '', initModal: (function() { var container = this.get('container'); - container.register('view:em-wysiwyg-action-link-modal', Modal.extend({ - layoutName: 'components/em-wysiwyg-action-link-modal', - configName: 'bs', - _parentView: this, - linkHref: computed.alias('parentView.linkHref'), - actions: { - addLink: function() { - this.get('parentView').send('addLink'); + if(!container.lookupFactory(COMPONENT_NAME)) { + container._registry.register(COMPONENT_NAME, Modal.extend({ + layoutName: 'components/em-wysiwyg-action-link-modal', + configName: 'bs', + _parentView: this, + linkHref: computed.alias('parentView.linkHref'), + actions: { + addLink: function() { + this.get('parentView').send('addLink'); + } } - } - })); - this.set('modal', container.lookup('view:em-wysiwyg-action-link-modal')); + })); + } + this.set('modal', container.lookup(COMPONENT_NAME)); return this.get('modal').append(); }).on('init'), styleClasses: (function() { @@ -70,4 +73,4 @@ export default Em.Component.extend(WithConfigMixin, { }; })(this)); }).on('init') -}); \ No newline at end of file +}); diff --git a/package.json b/package.json index df3edc1..f57b348 100644 --- a/package.json +++ b/package.json @@ -23,7 +23,6 @@ "ember-cli": "0.1.4", "ember-cli-content-security-policy": "0.3.0", "ember-cli-dependency-checker": "0.0.6", - "ember-cli-esnext": "0.1.1", "ember-cli-ic-ajax": "0.1.1", "ember-cli-inject-live-reload": "^1.3.0", "ember-cli-qunit": "0.1.2", @@ -43,7 +42,9 @@ "configPath": "tests/dummy/config" }, "dependencies": { - "ember-idx-utils": "^0.2.2", - "ember-idx-modal": "^0.1.3" + "broccoli-babel-transpiler": "^5.4.5", + "ember-cli-babel": "^5.1.5", + "ember-idx-modal": "^0.1.3", + "ember-idx-utils": "^0.2.2" } } diff --git a/tests/dummy/app/initializers/hightlightjs.js b/tests/dummy/app/initializers/hightlightjs.js index ff30903..b245980 100644 --- a/tests/dummy/app/initializers/hightlightjs.js +++ b/tests/dummy/app/initializers/hightlightjs.js @@ -1,12 +1,14 @@ import Em from 'ember'; -import Config from 'ember-idx-utils/config'; +import UtilsConfig from 'ember-idx-utils/config'; /*global hljs*/ +var Config; + export default { name: 'hightlightjs', initialize: function() { //In real app we don't need this coz the initializer of modal will be merged into the app and will run automatically - Em.Config = Config = Config.create(); + Em.Config = Config = UtilsConfig.create(); var defaultConfig = Config.getConfig('bs'); if (!defaultConfig) {