How to use the ember-metal/merge 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
function applyMergedProperties(obj, key, value, values) {
  var baseValue = values[key] || obj[key];

  Ember.assert(`You passed in \`${JSON.stringify(value)}\` as the value for \`${key}\` but \`${key}\` cannot be an Array`, !isArray(value));

  if (!baseValue) { return value; }

  var newBase = merge({}, baseValue);
  var hasFunction = false;

  for (var prop in value) {
    if (!value.hasOwnProperty(prop)) { continue; }

    var propValue = value[prop];
    if (isMethod(propValue)) {
      // TODO: support for Computed Properties, etc?
      hasFunction = true;
      newBase[prop] = giveMethodSuper(obj, prop, propValue, baseValue, {});
    } else {
      newBase[prop] = propValue;
    }
  }

  if (hasFunction) {
github emberjs / ember.js / packages / ember-metal / lib / streams / stream_binding.js View on Github external
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) {
      this.senderCallback = callback;
      this.senderContext = context;
github emberjs / ember.js / packages / ember-views / lib / streams / context_stream.js View on Github external
import merge from "ember-metal/merge";
import create from 'ember-metal/platform/create';
import { isGlobal } from "ember-metal/path_cache";
import Stream from "ember-metal/streams/stream";
import SimpleStream from "ember-metal/streams/simple";

function ContextStream(view) {
  Ember.assert("ContextStream error: the argument is not a view", view && view.isView);

  this.init();
  this.view = view;
}

ContextStream.prototype = create(Stream.prototype);

merge(ContextStream.prototype, {
  value() {},

  _makeChildStream(key, _fullPath) {
    var stream;

    if (key === '' || key === 'this') {
      stream = this.view._baseContext;
    } else if (isGlobal(key) && Ember.lookup[key]) {
      Ember.deprecate("Global lookup of " + _fullPath + " from a Handlebars template is deprecated.");
      stream = new SimpleStream(Ember.lookup[key]);
      stream._isGlobal = true;
    } else if (key in this.view._keywords) {
      stream = new SimpleStream(this.view._keywords[key]);
    } else {
      stream = new SimpleStream(this.view._baseContext.get(key));
    }
github emberjs / ember.js / packages / ember-htmlbars / lib / compat / helper.js View on Github external
this.helperFunction = function helperFunc(params, hash, options, env) {
    var param, blockResult, fnResult;
    var context = env.data.view;
    var handlebarsOptions = {
      hash: { },
      types: new Array(params.length),
      hashTypes: { }
    };

    merge(handlebarsOptions, options);
    merge(handlebarsOptions, env);

    handlebarsOptions.hash = {};

    if (options.isBlock) {
      handlebarsOptions.fn = function() {
        blockResult = options.template.render(context, env, options.morph.contextualElement);
      };

      if (options.inverse) {
        handlebarsOptions.inverse = function() {
          blockResult = options.inverse.render(context, env, options.morph.contextualElement);
        };
      }
    }
github emberjs / ember.js / packages / ember-views / lib / mixins / normalized_rerender_if_needed.js View on Github external
import { get } from "ember-metal/property_get";
import { Mixin } from 'ember-metal/mixin';
import merge from "ember-metal/merge";
import {
  cloneStates,
  states as viewStates
} from "ember-views/views/states";

var states = cloneStates(viewStates);

merge(states._default, {
  rerenderIfNeeded() { return this; }
});

merge(states.inDOM, {
  rerenderIfNeeded(view) {
    if (view.normalizedValue() !== view._lastNormalizedValue) {
      view.rerender();
    }
  }
});

export default Mixin.create({
  _states: states,

  normalizedValue() {
    var value = this.lazyValue.value();
    var valueNormalizer = get(this, 'valueNormalizerFunc');
    return valueNormalizer ? valueNormalizer(value) : value;
  },
github emberjs / ember.js / packages_es6 / ember-views / lib / views / states.js View on Github external
function cloneStates(from) {
  var into = {};

  into._default = {};
  into.preRender = create(into._default);
  into.destroying = create(into._default);
  into.inBuffer = create(into._default);
  into.hasElement = create(into._default);
  into.inDOM = create(into.hasElement);

  for (var stateName in from) {
    if (!from.hasOwnProperty(stateName)) { continue; }
    merge(into[stateName], from[stateName]);
  }

  return into;
};
github emberjs / ember.js / packages / ember-views / lib / views / states / destroying.js View on Github external
import merge from "ember-metal/merge";
import {create} from "ember-metal/platform";
import {fmt} from "ember-runtime/system/string";
import _default from "ember-views/views/states/default";
import EmberError from "ember-metal/error";
/**
@module ember
@submodule ember-views
*/

var destroyingError = "You can't call %@ on a view being destroyed";

var destroying = create(_default);

merge(destroying, {
  appendChild: function() {
    throw new EmberError(fmt(destroyingError, ['appendChild']));
  },
  rerender: function() {
    throw new EmberError(fmt(destroyingError, ['rerender']));
  },
  destroyElement: function() {
    throw new EmberError(fmt(destroyingError, ['destroyElement']));
  },
  empty: function() {
    throw new EmberError(fmt(destroyingError, ['empty']));
  },

  setElement: function() {
    throw new EmberError(fmt(destroyingError, ["set('element', ...)"]));
  },
github emberjs / ember.js / packages / ember-htmlbars / lib / node-managers / view-node-manager.js View on Github external
export function createOrUpdateComponent(component, options, createOptions, renderNode, env, attrs = {}) {
  let snapshot = takeSnapshot(attrs);
  let props = merge({}, options);
  let defaultController = View.proto().controller;
  let hasSuppliedController = 'controller' in attrs || 'controller' in props;

  if (!props.ownerView && options.parentView) {
    props.ownerView = options.parentView.ownerView;
  }

  props.attrs = snapshot;
  if (component.create) {
    let proto = component.proto();

    if (createOptions) {
      merge(props, createOptions);
    }

    mergeBindings(props, shadowedAttrs(proto, snapshot));
github emberjs / ember.js / packages / ember-views / lib / views / bound_view.js View on Github external
import { get } from "ember-metal/property_get";
import { set } from "ember-metal/property_set";
import merge from "ember-metal/merge";
import {
  cloneStates,
  states as viewStates
} from "ember-views/views/states";
import _MetamorphView from "ember-views/views/metamorph_view";
import { Mixin } from 'ember-metal/mixin';
import run from 'ember-metal/run_loop';

function K() { return this; }

var states = cloneStates(viewStates);

merge(states._default, {
  rerenderIfNeeded: K
});

merge(states.inDOM, {
  rerenderIfNeeded: function(view) {
    if (view.normalizedValue() !== view._lastNormalizedValue) {
      view.rerender();
    }
  }
});

var NormalizedRerenderIfNeededSupport = Mixin.create({
  _states: states,

  normalizedValue: function() {
    var value = this.lazyValue.value();