How to use the ember-metal/streams/utils.read function in ember-metal

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-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-htmlbars / lib / helpers / view.js View on Github external
propertiesFromHTMLOptions: function(hash, options, env) {
    var view    = env.data.view;
    var classes = read(hash['class']);

    var extensions = {
      helperName: options.helperName || ''
    };

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

    if (hash.tag) {
      extensions.tagName = hash.tag;
    }

    if (classes) {
      classes = classes.split(' ');
      extensions.classNames = classes;
    }

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

    if (hash.classNameBindings) {
github emberjs / ember.js / packages / ember-htmlbars / lib / helpers / input.js View on Github external
export function inputHelper(params, hash, options, env) {
  Ember.assert('You can only pass attributes to the `input` helper, not arguments', params.length === 0);

  var onEvent = hash.on;
  var inputType;

  inputType = read(hash.type);

  if (inputType === 'checkbox') {
    delete hash.type;

    Ember.assert("{{input type='checkbox'}} does not support setting `value=someBooleanValue`;" +
                 " you must use `checked=someBooleanValue` instead.", !hash.hasOwnProperty('value'));

    env.helpers.view.helperFunction.call(this, [Checkbox], hash, options, env);
  } else {
    delete hash.on;

    hash.onEvent = onEvent || 'enter';
    env.helpers.view.helperFunction.call(this, [TextField], hash, options, env);
  }
}
github emberjs / ember.js / packages / ember-views / lib / attr_nodes / legacy_bind.js View on Github external
LegacyBindAttrNode.prototype.render = function render(buffer) {
  this.isDirty = false;
  if (this.isDestroying) {
    return;
  }
  var value = read(this.attrValue);

  if (value === undefined) {
    value = null;
  }

  if ((this.attrName === 'value' || this.attrName === 'src') && value === null) {
    value = '';
  }

  Ember.assert(fmt("Attributes must be numbers, strings or booleans, not %@", [value]),
               value === null || value === undefined || typeOf(value) === 'number' || typeOf(value) === 'string' || typeOf(value) === 'boolean' || !!(value && value.toHTML));

  if (this.lastValue !== null || value !== null) {
    this._deprecateEscapedStyle(value);
    this._morph.setContent(value);
    this.lastValue = value;
github emberjs / ember.js / packages / ember-views / lib / views / bound_component_view.js View on Github external
_createNewComponent: function() {
    var componentClass = read(this.componentClassStream);
    if (!componentClass) {
      throw new EmberError('HTMLBars error: Could not find component named "' + read(this._boundComponentOptions.componentNameStream) + '".');
    }
    var hash    = this._boundComponentOptions;
    var hashForComponent = {};

    var prop;
    for (prop in hash) {
      if (prop === '_boundComponentOptions' || prop === 'componentClassStream') { continue; }
      hashForComponent[prop] = hash[prop];
    }

    var props   = {};
    mergeViewBindings(this, props, hashForComponent);
    return this.createChildView(componentClass, props);
  }
});
github emberjs / ember.js / packages / ember-views / lib / attr_nodes / attr_node.js View on Github external
AttrNode.prototype.render = function render(buffer) {
  this.isDirty = false;
  var value = read(this.attrValue);

  this._morph.setContent(value);

  this.lastValue = value;
};
github emberjs / ember.js / packages / ember-metal / lib / streams / conditional.js View on Github external
if (newTestResult !== oldTestResult) {
    switch (oldTestResult) {
      case true: unsubscribe(this.consequent, this.notify, this); break;
      case false: unsubscribe(this.alternate, this.notify, this); break;
      case undefined: subscribe(this.test, this.notify, this);
    }

    switch (newTestResult) {
      case true: subscribe(this.consequent, this.notify, this); break;
      case false: subscribe(this.alternate, this.notify, this);
    }

    this.oldTestResult = newTestResult;
  }

  return newTestResult ? read(this.consequent) : read(this.alternate);
};
github emberjs / ember.js / packages / ember-routing-views / lib / views / link.js View on Github external
function getResolvedQueryParams(linkView, targetRouteName) {
  var queryParamsObject = linkView.queryParamsObject;
  var resolvedQueryParams = {};

  if (!queryParamsObject) { return resolvedQueryParams; }

  var values = queryParamsObject.values;
  for (var key in values) {
    if (!values.hasOwnProperty(key)) { continue; }
    resolvedQueryParams[key] = read(values[key]);
  }

  return resolvedQueryParams;
}
github emberjs / ember.js / packages / ember-views / lib / attr_nodes / attr_node.js View on Github external
AttrNode.prototype.renderIfDirty = function renderIfDirty(){
  if (this.isDirty) {
    var value = read(this.attrValue);
    if (value !== this.lastValue) {
      this._renderer.renderTree(this, this._parentView);
    } else {
      this.isDirty = false;
    }
  }
};