Example #1
0
  this.helperFunction = function helperFunc(params, hash, options, env) {
    var param;
    var handlebarsOptions = {};
    merge(handlebarsOptions, options);
    merge(handlebarsOptions, env);

    handlebarsOptions.hash = {};
    for (var prop in hash) {
      param = hash[prop];

      if (isStream(param)) {
        handlebarsOptions.hash[prop] = param._label;
      } else {
        handlebarsOptions.hash[prop] = param;
      }
    }

    var args = new Array(params.length);
    for (var i = 0, l = params.length; i < l; i++) {
      param = params[i];

      if (isStream(param)) {
        args[i] = param._label;
      } else {
        args[i] = param;
      }
    }
    args.push(handlebarsOptions);

    return fn.apply(this, args);
  };
Example #2
0
  this.helperFunction = function helperFunc(params, hash, options, env) {
    var handlebarsOptions = {};
    merge(handlebarsOptions, options);
    merge(handlebarsOptions, env);
    handlebarsOptions.hash = options._raw.hash;

    var args = options._raw.params;
    args.push(handlebarsOptions);

    return fn.apply(this, args);
  };
Example #3
0
  this.helperFunction = function helperFunc(params, hash, options, env) {
    var param, blockResult, fnResult;
    var context = this;
    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);
      };
    }

    for (var prop in hash) {
      param = hash[prop];

      handlebarsOptions.hashTypes[prop] = calculateCompatType(param);

      if (isStream(param)) {
        handlebarsOptions.hash[prop] = param._label;
      } else {
        handlebarsOptions.hash[prop] = param;
      }
    }

    var args = new Array(params.length);
    for (var i = 0, l = params.length; i < l; i++) {
      param = params[i];

      handlebarsOptions.types[i] = calculateCompatType(param);

      if (isStream(param)) {
        args[i] = param._label;
      } else {
        args[i] = param;
      }
    }
    args.push(handlebarsOptions);

    fnResult = fn.apply(this, args);

    return options.isBlock ? blockResult : fnResult;
  };
  return instrument(component, function() {

    var newEnv = env;
    if (component) {
      newEnv = merge({}, env);
      newEnv.view = component;
    }

    if (component) {
      var snapshot = takeSnapshot(attrs);
      env.renderer.setAttrs(this.component, snapshot);
      env.renderer.willCreateElement(component);
      env.renderer.willRender(component);
      env.renderedViews.push(component.elementId);
    }

    if (this.block) {
      this.block(newEnv, [], undefined, this.renderNode, this.scope, visitor);
    }

    if (component) {
      var element = this.expectElement && this.renderNode.firstNode;
      env.renderer.didCreateElement(component, element); // 2.0TODO: Remove legacy hooks.
      env.renderer.willInsertElement(component, element);
      env.lifecycleHooks.push({ type: 'didInsertElement', view: component });
    }
  }, this);
  return instrument(component, function() {

    var newEnv = env;
    if (component) {
      newEnv = merge({}, env);
      newEnv.view = component;

      var snapshot = takeSnapshot(attrs);

      // Notify component that it has become dirty and is about to change.
      env.renderer.willUpdate(component, snapshot);

      if (component._renderNode.shouldReceiveAttrs) {
        env.renderer.updateAttrs(component, snapshot);
        setProperties(component, mergeBindings({}, shadowedAttrs(component, snapshot)));
        component._renderNode.shouldReceiveAttrs = false;
      }

      env.renderer.willRender(component);

      env.renderedViews.push(component.elementId);
    }

    if (this.block) {
      this.block(newEnv, [], undefined, this.renderNode, this.scope, visitor);
    }

    if (component) {
      env.lifecycleHooks.push({ type: 'didUpdate', view: component });
    }

    return newEnv;
  }, this);
Example #6
0
    function isActiveForRoute(routeName) {
      var handlers = router.router.recognizer.handlersFor(routeName);
      var leafName = handlers[handlers.length-1].handler;
      var maximumContexts = numberOfContextsAcceptedByHandler(routeName, handlers);

      // NOTE: any ugliness in the calculation of activeness is largely
      // due to the fact that we support automatic normalizing of
      // `resource` -> `resource.index`, even though there might be
      // dynamic segments / query params defined on `resource.index`
      // which complicates (and makes somewhat ambiguous) the calculation
      // of activeness for links that link to `resource` instead of
      // directly to `resource.index`.

      // if we don't have enough contexts revert back to full route name
      // this is because the leaf route will use one of the contexts
      if (contexts.length > maximumContexts) {
        routeName = leafName;
      }

      var args = routeArgs(routeName, contexts, null);
      var isActive = router.isActive.apply(router, args);
      if (!isActive) { return false; }

      if (Ember.FEATURES.isEnabled("query-params-new")) {
        if (!isCurrentWhenSpecified && leafName === loadedParams.targetRouteName) {
          var visibleQueryParams = {};
          merge(visibleQueryParams, loadedParams.queryParams);
          router._prepareQueryParams(loadedParams.targetRouteName, loadedParams.models, visibleQueryParams);
          isActive = shallowEqual(visibleQueryParams, router.router.state.queryParams);
        }
      }
      return isActive;
    }
Example #7
0
  setup: function(addedEvents, rootElement) {
    var event, events = get(this, 'events');

    merge(events, addedEvents || {});

    if (!isNone(rootElement)) {
      set(this, 'rootElement', rootElement);
    }

    rootElement = jQuery(get(this, 'rootElement'));

    Ember.assert(fmt('You cannot use the same root element (%@) multiple times in an Ember.Application', [rootElement.selector || rootElement[0].tagName]), !rootElement.is('.ember-application'));
    Ember.assert('You cannot make a new Ember.Application using a root element that is a descendent of an existing Ember.Application', !rootElement.closest('.ember-application').length);
    Ember.assert('You cannot make a new Ember.Application using a root element that is an ancestor of an existing Ember.Application', !rootElement.find('.ember-application').length);

    rootElement.addClass('ember-application');

    Ember.assert('Unable to add "ember-application" class to rootElement. Make sure you set rootElement to the body or an element in the body.', rootElement.is('.ember-application'));

    for (event in events) {
      if (events.hasOwnProperty(event)) {
        this.setupHandler(rootElement, event, events[event]);
      }
    }
  },
Example #8
0
  _queryParamsFor: function(leafRouteName) {
    if (this._qpCache[leafRouteName]) {
      return this._qpCache[leafRouteName];
    }

    var map = {}, qps = [], qpCache = this._qpCache[leafRouteName] = {
      map: map,
      qps: qps
    };

    var routerjs = this.router;
    var recogHandlerInfos = routerjs.recognizer.handlersFor(leafRouteName);

    for (var i = 0, len = recogHandlerInfos.length; i < len; ++i) {
      var recogHandler = recogHandlerInfos[i];
      var route = routerjs.getHandler(recogHandler.handler);
      var qpMeta = get(route, '_qp');

      if (!qpMeta) { continue; }

      merge(map, qpMeta.map);
      qps.push.apply(qps, qpMeta.qps);
    }

    return {
      qps: qps,
      map: map
    };
  },
Example #9
0
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) {
    newBase._super = superFunction;
  }

  return newBase;
}
Example #10
0
function applyMergedProperties(obj, key, value, values) {
  var baseValue = values[key] || obj[key];

  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) {
    newBase._super = superFunction;
  }

  return newBase;
}
Example #11
0
  willMergeMixin: function(props) {
    if (Ember.FEATURES.isEnabled('ember-metal-injected-properties')) {
      // Calling super is only OK here since we KNOW that there is another
      // Mixin loaded first (injection dependency verification)
      this._super.apply(this, arguments);
    }

    var hashName;

    if (!props._actions) {
      Ember.assert("'actions' should not be a function", typeof(props.actions) !== 'function');

      if (typeOf(props.actions) === 'object') {
        hashName = 'actions';
      } else if (typeOf(props.events) === 'object') {
        Ember.deprecate('Action handlers contained in an `events` object are deprecated in favor' +
                        ' of putting them in an `actions` object', false);
        hashName = 'events';
      }

      if (hashName) {
        props._actions = merge(props._actions || {}, props[hashName]);
      }

      delete props[hashName];
    }
  },
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));
    props.container = options.parentView ? options.parentView.container : env.container;
    props.renderer = options.parentView ? options.parentView.renderer : props.container && props.container.lookup('renderer:-dom');
    props._viewRegistry = options.parentView ? options.parentView._viewRegistry : props.container && props.container.lookup('-view-registry:main');

    if (proto.controller !== defaultController || hasSuppliedController) {
      delete props._context;
    }

    component = component.create(props);
  } else {
    env.renderer.componentUpdateAttrs(component, snapshot);
    mergeBindings(props, shadowedAttrs(component, snapshot));
    setProperties(component, props);
  }

  if (options.parentView) {
    options.parentView.appendChild(component);

    if (options.viewName) {
      set(options.parentView, options.viewName, component);
    }
  }

  component._renderNode = renderNode;

  renderNode.emberView = component;
  return component;
}
Example #13
0
QUnit.test("HTMLBars is present and can be executed", function() {
  var template = compile("ohai");

  var env = merge({ dom: domHelper }, defaultEnv);

  var output = template.render({}, env, document.body);
  equalHTML(output, "ohai");
});
Example #14
0
function mockBrowserHistory(overrides) {
  AutoTestLocation._history = merge({
    pushState: function () {
      ok(false, 'history.pushState should not be called during testing');
    },
    replaceState: function () {
      ok(false, 'history.replaceState should not be called during testing');
    }
  }, overrides);
}
function createRouter(overrides, disableSetup) {
  var opts = merge({ container: container }, overrides);
  var routerWithContainer = Router.extend();
  var router = routerWithContainer.create(opts);

  if (!disableSetup) {
    router.setupRouter();
  }

  return router;
}
Example #16
0
function mockBrowserLocation(overrides) {
  return merge({
    href: 'http://test.com/',
    pathname: '/',
    hash: '',
    search: '',
    replace() {
      ok(false, 'location.replace should not be called during testing');
    }
  }, overrides);
}
Example #17
0
function computeQueryParams(linkView, stripDefaultValues) {
  var helperParameters = linkView.parameters,
      queryParamsObject = get(linkView, 'queryParamsObject'),
      suppliedParams = {};

  if (queryParamsObject) {
    merge(suppliedParams, queryParamsObject.values);
  }

  var resolvedParams = get(linkView, 'resolvedParams'),
      router = get(linkView, 'router'),
      routeName = resolvedParams[0],
      paramsForRoute = router._queryParamsFor(routeName),
      qps = paramsForRoute.qps,
      paramsForRecognizer = {};

  // We need to collect all non-default query params for this route.
  for (var i = 0, len = qps.length; i < len; ++i) {
    var qp = qps[i];

    // Check if the link-to provides a value for this qp.
    var providedType = null, value;
    if (qp.prop in suppliedParams) {
      value = suppliedParams[qp.prop];
      providedType = queryParamsObject.types[qp.prop];
      delete suppliedParams[qp.prop];
    } else if (qp.urlKey in suppliedParams) {
      value = suppliedParams[qp.urlKey];
      providedType = queryParamsObject.types[qp.urlKey];
      delete suppliedParams[qp.urlKey];
    }

    if (providedType) {
      if (providedType === 'ID') {
        var normalizedPath = EmberHandlebars.normalizePath(helperParameters.context, value, helperParameters.options.data);
        value = EmberHandlebars.get(normalizedPath.root, normalizedPath.path, helperParameters.options);
      }

      value = qp.route.serializeQueryParam(value, qp.urlKey, qp.type);
    } else {
      value = qp.svalue;
    }

    if (stripDefaultValues && value === qp.sdef) {
      continue;
    }

    paramsForRecognizer[qp.urlKey] = value;
  }

  return paramsForRecognizer;
}
    removedItem: function (array, item, changeMeta, instanceMeta) {
      var proxyProperties, index, searchItem;

      if (changeMeta.previousValues) {
        proxyProperties = merge({ content: item }, changeMeta.previousValues);

        searchItem = SearchProxy.create(proxyProperties);
      } else {
        searchItem = item;
      }

      index = instanceMeta.binarySearch(array, searchItem);
      array.removeAt(index);
      return array;
    }
Example #19
0
  _doTransition: function(_targetRouteName, models, _queryParams) {
    var targetRouteName = _targetRouteName || getActiveTargetName(this.router);
    Ember.assert("The route " + targetRouteName + " was not found", targetRouteName && this.router.hasRoute(targetRouteName));

    var queryParams = {};
    merge(queryParams, _queryParams);
    this._prepareQueryParams(targetRouteName, models, queryParams);

    var transitionArgs = routeArgs(targetRouteName, models, queryParams);
    var transitionPromise = this.router.transitionTo.apply(this.router, transitionArgs);

    listenForTransitionErrors(transitionPromise);

    return transitionPromise;
  },
Example #20
0
export function cloneStates(from) {
  var into = {};

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

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

  return into;
}
Example #21
0
  href: computed('loadedParams', function computeLinkViewHref() {
    if (get(this, 'tagName') !== 'a') { return; }

    var router = get(this, 'router');
    var loadedParams = get(this, 'loadedParams');

    if (!loadedParams) {
      return get(this, 'loadingHref');
    }

    var visibleQueryParams = {};
    merge(visibleQueryParams, loadedParams.queryParams);
    router._prepareQueryParams(loadedParams.targetRouteName, loadedParams.models, visibleQueryParams);

    var args = routeArgs(loadedParams.targetRouteName, loadedParams.models, visibleQueryParams);
    var result = router.generate.apply(router, args);
    return result;
  }),
Example #22
0
ComponentNode.prototype.render = function(env, attrs, visitor) {
  var component = this.component;

  var newEnv = env;
  if (component) {
    newEnv = merge({}, env);
    newEnv.view = component;
  }

  if (component) {
    var snapshot = takeSnapshot(attrs);
    env.renderer.setAttrs(this.component, snapshot);
    env.renderer.willCreateElement(component);
    env.renderer.willRender(component);
    env.renderedViews.push(component.elementId);
  }

  if (this.block) {
    this.block(newEnv, [], undefined, this.renderNode, this.scope, visitor);
  }

  if (component) {
    var element = this.expectElement && this.renderNode.firstNode;
    if (component.render) {
      var content, node, lastChildIndex;
      var buffer = [];
      component.render(buffer);
      content = buffer.join('');
      if (element) {
        lastChildIndex = this.renderNode.childNodes.length - 1;
        node = this.renderNode.childNodes[lastChildIndex];
      } else {
        node = this.renderNode;
      }
      node.setContent(new SafeString(content));
    }

    env.renderer.didCreateElement(component, element); // 2.0TODO: Remove legacy hooks.
    env.renderer.willInsertElement(component, element);
    env.lifecycleHooks.push({ type: 'didInsertElement', view: component });
  }
};
Example #23
0
  willMergeMixin: function(props) {
    var hashName;

    if (!props._actions) {
      Ember.assert("'actions' should not be a function", typeof(props.actions) !== 'function');

      if (typeOf(props.actions) === 'object') {
        hashName = 'actions';
      } else if (typeOf(props.events) === 'object') {
        Ember.deprecate('Action handlers contained in an `events` object are deprecated in favor of putting them in an `actions` object', false);
        hashName = 'events';
      }

      if (hashName) {
        props._actions = merge(props._actions || {}, props[hashName]);
      }

      delete props[hashName];
    }
  },
Example #24
0
function accumulateQueryParamDescriptors(_desc, accum) {
  var desc = _desc, tmp;
  if (typeOf(desc) === 'string') {
    tmp = {};
    tmp[desc] = { as: null };
    desc = tmp;
  }

  for (var key in desc) {
    if (!desc.hasOwnProperty(key)) { return; }

    var singleDesc = desc[key];
    if (typeOf(singleDesc) === 'string') {
      singleDesc = { as: singleDesc };
    }

    tmp = accum[key] || { as: null, scope: 'model' };
    merge(tmp, singleDesc);

    accum[key] = tmp;
  }
}
export function createOrUpdateComponent(component, options, renderNode, env, attrs = {}) {
  let snapshot = takeSnapshot(attrs);
  let props = merge({}, options);
  let defaultController = View.proto().controller;
  let hasSuppliedController = 'controller' in attrs;

  props.attrs = snapshot;

  if (component.create) {
    let proto = component.proto();
    mergeBindings(props, shadowedAttrs(proto, snapshot));
    props.container = options.parentView ? options.parentView.container : env.container;

    if (proto.controller !== defaultController || hasSuppliedController) {
      delete props._context;
    }

    component = component.create(props);
  } else {
    mergeBindings(props, shadowedAttrs(component, snapshot));
    setProperties(component, props);
  }

  if (options.parentView) {
    options.parentView.appendChild(component);

    if (options.viewName) {
      set(options.parentView, options.viewName, component);
    }
  }

  component._renderNode = renderNode;
  renderNode.emberComponent = component;
  renderNode.emberView = component;
  return component;
}
Example #26
0
ShouldDisplayStream.prototype = Object.create(Stream.prototype);

merge(ShouldDisplayStream.prototype, {
  compute() {
    var truthy = read(this.isTruthy);

    if (typeof truthy === 'boolean') {
      return truthy;
    }

    if (this.lengthDep) {
      return this.lengthDep.getValue() !== 0;
    } else {
      return !!read(this.predicate);
    }
  },

  revalidate() {
    if (isArray(read(this.predicate))) {
      if (!this.lengthDep) {
        this.lengthDep = this.addMutableDependency(this.predicate.get('length'));
      }
    } else {
      if (this.lengthDep) {
        this.lengthDep.destroy();
        this.lengthDep = null;
      }
    }
  }
});
Example #27
0
    env.hooks.range(morph, env, scope, null, valueStream);
  } else if (template === null) {
    env.hooks.inline(morph, env, scope, valueStream.key, params, hash);
  } else {
    env.hooks.block(morph, env, scope, valueStream.key, params, hash, template, inverse);
  }

  return true;
}

import merge from 'ember-metal/merge';
import Stream from 'ember-metal/streams/stream';
import { read } from 'ember-metal/streams/utils';

function VolatileStream(source) {
  this.init(`(volatile ${source.label})`);
  this.source = source;

  this.addDependency(source);
}

VolatileStream.prototype = Object.create(Stream.prototype);

merge(VolatileStream.prototype, {
  value() {
    return read(this.source);
  },

  notify() {}
});
Example #28
0
  _pruneDefaultQueryParamValues(targetRouteName, queryParams) {
    var qps = this._queryParamsFor(targetRouteName);
    for (var key in queryParams) {
      var qp = qps.map[key];
      if (qp && qp.sdef === queryParams[key]) {
        delete queryParams[key];
      }
    }
  },

  _doTransition(_targetRouteName, models, _queryParams) {
    var targetRouteName = _targetRouteName || getActiveTargetName(this.router);
    Ember.assert("The route " + targetRouteName + " was not found", targetRouteName && this.router.hasRoute(targetRouteName));

    var queryParams = {};
    merge(queryParams, _queryParams);
    this._prepareQueryParams(targetRouteName, models, queryParams);

    var transitionArgs = routeArgs(targetRouteName, models, queryParams);
    var transitionPromise = this.router.transitionTo.apply(this.router, transitionArgs);

    didBeginTransition(transitionPromise, this);

    return transitionPromise;
  },

  _prepareQueryParams(targetRouteName, models, queryParams) {
    this._hydrateUnsuppliedQueryParams(targetRouteName, models, queryParams);
    this._serializeQueryParams(targetRouteName, queryParams);
    this._pruneDefaultQueryParamValues(targetRouteName, queryParams);
  },
Example #29
0
merge(inDOM, {
  enter(view) {
    // Register the view for event handling. This hash is used by
    // Ember.EventDispatcher to dispatch incoming events.
    if (view.tagName !== '') {
      view._register();
    }

    Ember.runInDebug(function() {
      addBeforeObserver(view, 'elementId', function() {
        throw new EmberError('Changing a view\'s elementId after creation is not allowed');
      });
    });
  },

  exit(view) {
    view._unregister();
  },

  appendAttr(view, attrNode) {
    var childViews = view.childViews;

    if (!childViews.length) { childViews = view.childViews = childViews.slice(); }
    childViews.push(attrNode);

    attrNode.parentView = view;
    view.renderer.appendAttrTo(attrNode, view.element, attrNode.attrName);

    view.propertyDidChange('childViews');

    return attrNode;
  }

});
Example #30
0
merge(inBuffer, {
  $: function(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: function(view) {
    throw new EmberError("Something you did caused a view to re-render after it rendered but before it was inserted into the DOM.");
  },

  // when a view is rendered in a buffer, appending a child
  // view will render that view and append the resulting
  // buffer into its buffer.
  appendChild: function(view, childView, options) {
    var buffer = view.buffer;
    var _childViews = view._childViews;

    childView = view.createChildView(childView, options);
    if (!_childViews.length) { _childViews = view._childViews = _childViews.slice(); }
    _childViews.push(childView);

    if (!childView._morph) {
      buffer.pushChildView(childView);
    }

    view.propertyDidChange('childViews');

    return childView;
  },

  invokeObserver: function(target, observer) {
    observer.call(target);
  }
});