Skip to content

Instantly share code, notes, and snippets.

@listepo
Last active September 24, 2015 20:16
Show Gist options
  • Save listepo/b48ba4bca5a3361ea94e to your computer and use it in GitHub Desktop.
Save listepo/b48ba4bca5a3361ea94e to your computer and use it in GitHub Desktop.
Mixin(Ember.js) for application controller/component
import Ember from 'ember';
export default Ember.Mixin.create({
uiSettings: null,
init() {
let uiSettings = this.get('uiSettings');
if (!Ember.$.isPlainObject(uiSettings)) {
throw new Ember.Error('uiSettings must be object');
}
Ember.$.each(uiSettings, (moduleName, settings) => {
let Module = Ember.$.fn[moduleName];
if (!Ember.$.isPlainObject(Module.settings)) {
throw new Ember.Error('Module must have settings object');
}
Module.settings = Ember.$.extend(true, Module.settings, settings);
});
this._super();
}
});
@listepo
Copy link
Author

listepo commented Sep 24, 2015

Use:

import Ember from 'ember';
import SemanticSettings from 'web/mixins/semantic-settings';

export default Ember.Component.extend(SemanticSettings, {
  uiSettings: {
    form: {
      inline: true,
      prompt: {
        empty: 'Some text'
      }
    }
  }
});

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment