How to use ember-metal - 10 common examples

To help you get started, we’ve selected a few ember-metal examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github emberjs / ember.js / packages / ember-handlebars / lib / helpers / view.js View on Github external
extensions.classNames = classes;
    }

    if (hash.classBinding) {
      extensions.classNameBindings = hash.classBinding.split(' ');
    }

    if (hash.classNameBindings) {
      if (extensions.classNameBindings === undefined) {
        extensions.classNameBindings = [];
      }
      extensions.classNameBindings = extensions.classNameBindings.concat(hash.classNameBindings.split(' '));
    }

    if (hash.attributeBindings) {
      Ember.assert("Setting 'attributeBindings' via template helpers is not allowed." +
                   " Please subclass Ember.View and set it there instead.");
      extensions.attributeBindings = null;
    }

    // Set the proper context for all bindings passed to the helper. This applies to regular attribute bindings
    // as well as class name bindings. If the bindings are local, make them relative to the current context
    // instead of the view.

    var hashKeys = keys(hash);

    for (var i = 0, l = hashKeys.length; i < l; i++) {
      var prop = hashKeys[i];

      if (prop !== 'classNameBindings') {
        extensions[prop] = hash[prop];
      }
github emberjs / ember.js / packages / ember-runtime / lib / controllers / array_controller.js View on Github external
replace(subControllers, idx, removedCnt, new Array(addedCnt));
    }

    // The shadow array of subcontrollers must be updated before we trigger
    // observers, otherwise observers will get the wrong subcontainer when
    // calling `objectAt`
    this._super(idx, removedCnt, addedCnt);
  },

  init() {
    this._super(...arguments);
    this._subControllers = [];
  },

  model: computed({
    get(key) {
      return Ember.A();
    },
    set(key, value) {
      Ember.assert(
        'ArrayController expects `model` to implement the Ember.Array mixin. ' +
        'This can often be fixed by wrapping your model with `Ember.A()`.',
        EmberArray.detect(value) || !value
      );

      return value;
    }
  }),

  /**
   * Flag to mark as being "virtual". Used to keep this instance
github emberjs / ember.js / packages / ember-htmlbars / lib / helpers / view.js View on Github external
for (var prop in hash) {
    var value = hash[prop];

    // Classes are processed separately
    if (prop === 'class' && isStream(value)) {
      hash.classBinding = value._label;
      delete hash['class'];
      continue;
    }

    if (prop === 'classBinding') {
      continue;
    }

    if (IS_BINDING.test(prop)) {
      if (isStream(value)) {
        Ember.warn("You're attempting to render a view by passing " +
                   prop + " " +
                   "to a view helper without a quoted value, " +
                   "but this syntax is ambiguous. You should either surround " +
                   prop + "'s value in quotes or remove `Binding` " +
                   "from " + prop + ".");
      } else if (typeof value === 'string') {
        hash[prop] = view._getBindingForStream(value);
      }
    } else {
      if (isStream(value) && prop !== 'id') {
        hash[prop + 'Binding'] = view._getBindingForStream(value);
        delete hash[prop];
      }
    }
  }
github emberjs / ember.js / packages / ember-htmlbars / lib / helpers / view.js View on Github external
function makeBindings(hash, options, view) {
  for (var prop in hash) {
    var value = hash[prop];

    // Classes are processed separately
    if (prop === 'class' && isStream(value)) {
      hash.classBinding = value._label;
      delete hash['class'];
      continue;
    }

    if (prop === 'classBinding') {
      continue;
    }

    if (IS_BINDING.test(prop)) {
      if (isStream(value)) {
        Ember.warn("You're attempting to render a view by passing " +
                   prop + " " +
                   "to a view helper without a quoted value, " +
                   "but this syntax is ambiguous. You should either surround " +
                   prop + "'s value in quotes or remove `Binding` " +
github emberjs / ember.js / packages / ember-htmlbars / lib / system / merge-view-bindings.js View on Github external
function mergeDOMViewBindings(view, props, hash) {
  Ember.assert(
    "Setting 'attributeBindings' via template helpers is not allowed. " +
    "Please subclass Ember.View and set it there instead.",
    !hash.attributeBindings
  );

  if (hash.id) {
    props.id = props.elementId = read(hash.id);
  }

  if (hash.tag) {
    props.tagName = read(hash.tag);
  }

  var classBindings = [];

  if (hash['class']) {
    if (typeof hash['class'] === 'string') {
      props.classNames = hash['class'].split(' ');
    } else if (hash['class']._label) {
      // label exists for via property paths in the template
      // but not for streams with nested sub-expressions
      classBindings.push(hash['class']._label);
    } else {
github emberjs / ember.js / packages / ember-views / lib / mixins / view_child_views_support.js View on Github external
/**
@module ember
@submodule ember-views
*/
import { assert } from 'ember-metal/debug';
import { Mixin } from 'ember-metal/mixin';
import { get } from 'ember-metal/property_get';
import { set } from 'ember-metal/property_set';
import setProperties from 'ember-metal/set_properties';
import { A as emberA } from 'ember-runtime/system/native_array';
import { getOwner, setOwner, OWNER } from 'container/owner';

const EMPTY_ARRAY = [];

export default Mixin.create({
  /**
    Array of child views. You should never edit this array directly.

    @property childViews
    @type Array
    @default []
    @private
  */
  childViews: EMPTY_ARRAY,

  init() {
    this._super(...arguments);

    // setup child views. be sure to clone the child views array first
    // 2.0TODO: Remove Ember.A() here
    this.childViews = emberA(this.childViews.slice());
github hummingbird-me / hummingbird-client / app / components / media / media-relationships.js View on Github external
mediaRelationships.forEach((relationship) => {
      const role = get(relationship, 'role');
      results[role] = results[role] || [];
      results[role].addObject(get(relationship, 'destination'));
    });
    // sort the results by key
github emberjs / ember.js / packages / ember-views / lib / views / select.js View on Github external
value.then(function (resolved) {
        // Ensure that we don't overwrite new value
        if (get(self, 'value') === value) {
          self._setSelectedIndex(resolved);
        }
      });
    } else {
github Ticketfly / ember-ticketfly-accordion / addon / utils / accordion-panel-animation.js View on Github external
animation.onfinish = function _panelCloseOnfinish() {

    // Before removing the panel body element from the accessibility tree and hiding
    // setting it to `display: none`, we need to restore its measurements so that they
    // can be read properly on the next "show"
    panelBodyElem.animate(
      [
        { height: '0px', paddingTop: '0px', paddingBottom: '0px', visibility: 'hidden' },
        { height, paddingTop, paddingBottom, visibility: 'visible' }
      ],
      { duration: 0.0001, fill: 'forwards' }
    );

    if (!get(panelBodyComponent, 'isDestroyed')) {
      set(panelBodyComponent, 'isPanelExpanded', false);
      onComplete(panelComponent);
    }
  };
github emberjs / ember.js / packages / ember-routing-htmlbars / lib / helpers / render.js View on Github external
export function renderHelper(params, hash, options, env) {
  var currentView = env.data.view;
  var container, router, controller, view, initialContext;

  var name = params[0];
  var context = params[1];

  container = currentView._keywords.controller.value().container;
  router = container.lookup('router:main');

  Ember.assert(
    "The first argument of {{render}} must be quoted, e.g. {{render \"sidebar\"}}.",
    typeof name === 'string'
  );

  Ember.assert(
    "The second argument of {{render}} must be a path, e.g. {{render \"post\" post}}.",
    params.length < 2 || isStream(params[1])
  );


  if (params.length === 1) {
    // use the singleton controller
    Ember.assert(
      "You can only use the {{render}} helper once without a model object as " +
      "its second argument, as in {{render \"post\" post}}.",
      !router || !router._lookupActiveView(name)