How to use the ember-metal/platform/create 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-metal / lib / mixin.js View on Github external
});
  };

  var didChange = function() {
    stream.setValue(get(obj, key), onNotify);
  };

  // Initialize value
  set(obj, key, stream.value());

  addObserver(obj, key, null, didChange);

  stream.subscribe(onNotify);

  if (obj._streamBindingSubscriptions === undefined) {
    obj._streamBindingSubscriptions = o_create(null);
  }

  obj._streamBindingSubscriptions[key] = onNotify;
}
github emberjs / ember.js / packages / ember-views / lib / views / states / in_buffer.js View on Github external
import _default from "ember-views/views/states/default";
import EmberError from "ember-metal/error";

import jQuery from "ember-views/system/jquery";
import create from 'ember-metal/platform/create';
import merge from "ember-metal/merge";

/**
@module ember
@submodule ember-views
*/

var inBuffer = create(_default);

merge(inBuffer, {
  $(view, sel) {
    // if we don't have an element yet, someone calling this.$() is
    // trying to update an element that isn't in the DOM. Instead,
    // rerender the view to allow the render method to reflect the
    // changes.
    view.rerender();
    return jQuery();
  },

  // when a view is rendered in a buffer, rerendering it simply
  // replaces the existing buffer with a new one
  rerender(view) {
    throw new EmberError("Something you did caused a view to re-render after it rendered but before it was inserted into the DOM.");
  },
github emberjs / ember.js / packages / ember-metal / lib / streams / stream_binding.js View on Github external
import run from "ember-metal/run_loop";
import Stream from "ember-metal/streams/stream";

function StreamBinding(stream) {
  Ember.assert("StreamBinding error: tried to bind to object that is not a stream", stream && stream.isStream);

  this.init();
  this.stream = stream;
  this.senderCallback = undefined;
  this.senderContext = undefined;
  this.senderValue = undefined;

  stream.subscribe(this._onNotify, this);
}

StreamBinding.prototype = create(Stream.prototype);

merge(StreamBinding.prototype, {
  valueFn: function() {
    return this.stream.value();
  },

  _onNotify: function() {
    this._scheduleSync(undefined, undefined, this);
  },

  setValue: function(value, callback, context) {
    this._scheduleSync(value, callback, context);
  },

  _scheduleSync: function(value, callback, context) {
    if (this.senderCallback === undefined && this.senderContext === undefined) {
github emberjs / ember.js / packages / ember-views / lib / attr_nodes / legacy_bind.js View on Github external
/**
@module ember
@submodule ember-htmlbars
*/

import AttrNode from "./attr_node";
import { fmt } from "ember-runtime/system/string";
import { typeOf } from "ember-metal/utils";
import { read } from "ember-metal/streams/utils";
import o_create from "ember-metal/platform/create";

function LegacyBindAttrNode(attrName, attrValue) {
  this.init(attrName, attrValue);
}

LegacyBindAttrNode.prototype = o_create(AttrNode.prototype);

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 = '';
  }
github emberjs / ember.js / packages / ember-metal / lib / mixin.js View on Github external
function mixinsMeta(obj) {
  var m = metaFor(obj, true);
  var ret = m.mixins;
  if (!ret) {
    ret = m.mixins = {};
  } else if (!m.hasOwnProperty('mixins')) {
    ret = m.mixins = o_create(ret);
  }
  return ret;
}
github emberjs / ember.js / packages / ember-metal / lib / utils.js View on Github external
if (Ember.FEATURES.isEnabled('mandatory-setter')) {
      if (hasPropertyAccessors) {
        ret.values = {};
      }
    }

    obj.__ember_meta__ = ret;
  } else if (ret.source !== obj) {
    if (obj.__defineNonEnumerable) {
      obj.__defineNonEnumerable(EMBER_META_PROPERTY);
    } else {
      o_defineProperty(obj, '__ember_meta__', META_DESC);
    }

    ret = o_create(ret);
    ret.watching  = o_create(ret.watching);
    ret.cache     = undefined;
    ret.cacheMeta = undefined;
    ret.source    = obj;

    if (Ember.FEATURES.isEnabled('mandatory-setter')) {
      if (hasPropertyAccessors) {
        ret.values = o_create(ret.values);
      }
    }

    obj['__ember_meta__'] = ret;
  }
  return ret;
}
github emberjs / ember.js / packages / ember-routing-htmlbars / lib / helpers / render.js View on Github external
view.setOutletState = function(state) {
    var ownState;
    if (state && (ownState = state.outlets[this._matchOutletName])) {
      this._outletState = {
        render: { name: 'render helper stub' },
        outlets: create(null)
      };
      this._outletState.outlets[ownState.render.outlet] = ownState;
      ownState.wasUsed = true;
    } else {
      this._outletState = null;
    }
    for (var i = 0; i < this._childOutlets.length; i++) {
      var child = this._childOutlets[i];
      child.setOutletState(this._outletState && this._outletState.outlets[child._outletName]);
    }
  };
github emberjs / ember.js / packages / ember-metal / lib / utils.js View on Github external
} else if (ret.source !== obj) {
    if (obj.__defineNonEnumerable) {
      obj.__defineNonEnumerable(EMBER_META_PROPERTY);
    } else {
      o_defineProperty(obj, '__ember_meta__', META_DESC);
    }

    ret = o_create(ret);
    ret.watching  = o_create(ret.watching);
    ret.cache     = undefined;
    ret.cacheMeta = undefined;
    ret.source    = obj;

    if (Ember.FEATURES.isEnabled('mandatory-setter')) {
      if (hasPropertyAccessors) {
        ret.values = o_create(ret.values);
      }
    }

    obj['__ember_meta__'] = ret;
  }
  return ret;
}