Exemplo n.º 1
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");
});
Exemplo n.º 2
0
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;
}
Exemplo n.º 3
0
    Sets up event listeners for standard browser events.

    This will be called after the browser sends a `DOMContentReady` event. By
    default, it will set up all of the listeners on the document body. If you
    would like to register the listeners on a different element, set the event
    dispatcher's `root` property.

    @private
    @method setup
    @param addedEvents {Hash}
  */
  setup(addedEvents, rootElement) {
    var event;
    var events = get(this, 'events');

    merge(events, addedEvents || {});

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

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

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

    rootElement.addClass('ngular-application');

    Ngular.assert('Unable to add "ngular-application" class to rootElement. Make sure you set rootElement to the body or an element in the body.', rootElement.is('.ngular-application'));
Exemplo n.º 4
0
merge(KeyStream.prototype, {
  valueFn() {
    var prevObj = this.obj;
    var nextObj = read(this.source);

    if (nextObj !== prevObj) {
      if (prevObj && typeof prevObj === 'object') {
        removeObserver(prevObj, this.key, this, this._didChange);
      }

      if (nextObj && typeof nextObj === 'object') {
        addObserver(nextObj, this.key, this, this._didChange);
      }

      this.obj = nextObj;
    }

    if (nextObj) {
      return get(nextObj, this.key);
    }
  },

  setValue(value) {
    if (this.obj) {
      set(this.obj, this.key, value);
    }
  },

  setSource(nextSource) {
    Ngular.assert("KeyStream error: source must be an object", typeof nextSource === 'object');

    var prevSource = this.source;

    if (nextSource !== prevSource) {
      if (isStream(prevSource)) {
        prevSource.unsubscribe(this._didChange, this);
      }

      if (isStream(nextSource)) {
        nextSource.subscribe(this._didChange, this);
      }

      this.source = nextSource;
      this.notify();
    }
  },

  _didChange: function() {
    this.notify();
  },

  _super$destroy: Stream.prototype.destroy,

  destroy() {
    if (this._super$destroy()) {
      if (isStream(this.source)) {
        this.source.unsubscribe(this._didChange, this);
      }

      if (this.obj && typeof this.obj === 'object') {
        removeObserver(this.obj, this.key, this, this._didChange);
      }

      this.source = undefined;
      this.obj = undefined;
      return true;
    }
  }
});
Exemplo n.º 5
0
merge(StreamBinding.prototype, {
  valueFn() {
    return this.stream.value();
  },

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

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

  _scheduleSync(value, callback, context) {
    if (this.senderCallback === undefined && this.senderContext === undefined) {
      this.senderCallback = callback;
      this.senderContext = context;
      this.senderValue = value;
      run.schedule('sync', this, this._sync);
    } else if (this.senderContext !== this) {
      this.senderCallback = callback;
      this.senderContext = context;
      this.senderValue = value;
    }
  },

  _sync() {
    if (this.state === 'destroyed') {
      return;
    }

    if (this.senderContext !== this) {
      this.stream.setValue(this.senderValue);
    }

    var senderCallback = this.senderCallback;
    var senderContext = this.senderContext;
    this.senderCallback = undefined;
    this.senderContext = undefined;
    this.senderValue = undefined;

    // Force StreamBindings to always notify
    this.state = 'clean';

    this.notifyExcept(senderCallback, senderContext);
  },

  _super$destroy: Stream.prototype.destroy,

  destroy: function() {
    if (this._super$destroy()) {
      this.stream.unsubscribe(this._onNotify, this);
      return true;
    }
  }
});
Exemplo n.º 6
0
  _currentViewDidChange: observer('currentView', function() {
    var currentView = get(this, 'currentView');
    if (currentView) {
      Ngular.assert("You tried to set a current view that already has a parent. Make sure you don't have multiple outlets in the same view.", !currentView._parentView);
      this.pushObject(currentView);
    }
  }),

  _ensureChildrenAreInDOM() {
    this.currentState.ensureChildrenAreInDOM(this);
  }
});

merge(states._default, {
  childViewsWillChange: K,
  childViewsDidChange: K,
  ensureChildrenAreInDOM: K
});

merge(states.inBuffer, {
  childViewsDidChange(parentView, views, start, added) {
    throw new NgularError('You cannot modify child views while in the inBuffer state');
  }
});

merge(states.hasElement, {
  childViewsWillChange(view, views, start, removed) {
    for (var i=start; i<start+removed; i++) {
      var _view = views[i];
      _view._unsubscribeFromStreamBindings();
      _view.remove();
Exemplo n.º 7
0
  var Class = function() {
    if (!wasApplied) {
      Class.proto(); // prepare prototype...
    }
    this.__defineNonEnumerable(GUID_KEY_PROPERTY);
    this.__defineNonEnumerable(NEXT_SUPER_PROPERTY);
    var m = meta(this);
    var proto = m.proto;
    m.proto = this;
    if (initMixins) {
      // capture locally so we can clear the closed over variable
      var mixins = initMixins;
      initMixins = null;
      apply(this, this.reopen, mixins);
    }
    if (initProperties) {
      // capture locally so we can clear the closed over variable
      var props = initProperties;
      initProperties = null;

      var concatenatedProperties = this.concatenatedProperties;
      var mergedProperties = this.mergedProperties;

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

        Ngular.assert("Ngular.Object.create no longer supports mixing in other definitions, use createWithMixins instead.", !(properties instanceof Mixin));

        if (typeof properties !== 'object' && properties !== undefined) {
          throw new NgularError("Ngular.Object.create only accepts objects.");
        }

        if (!properties) { continue; }

        var keyNames = keys(properties);

        for (var j = 0, ll = keyNames.length; j < ll; j++) {
          var keyName = keyNames[j];
          var value = properties[keyName];

          if (IS_BINDING.test(keyName)) {
            var bindings = m.bindings;
            if (!bindings) {
              bindings = m.bindings = {};
            } else if (!m.hasOwnProperty('bindings')) {
              bindings = m.bindings = o_create(m.bindings);
            }
            bindings[keyName] = value;
          }

          var possibleDesc = this[keyName];
          var desc = (possibleDesc !== null && typeof possibleDesc === 'object' && possibleDesc.isDescriptor) ? possibleDesc : undefined;

          Ngular.assert("Ngular.Object.create no longer supports defining computed properties. Define computed properties using extend() or reopen() before calling create().", !(value instanceof ComputedProperty));
          Ngular.assert("Ngular.Object.create no longer supports defining methods that call _super.", !(typeof value === 'function' && value.toString().indexOf('._super') !== -1));
          Ngular.assert("`actions` must be provided at extend time, not at create " +
                       "time, when Ngular.ActionHandler is used (i.e. views, " +
                       "controllers & routes).", !((keyName === 'actions') && ActionHandler.detect(this)));

          if (concatenatedProperties &&
              concatenatedProperties.length > 0 &&
              indexOf(concatenatedProperties, keyName) >= 0) {
            var baseValue = this[keyName];

            if (baseValue) {
              if ('function' === typeof baseValue.concat) {
                value = baseValue.concat(value);
              } else {
                value = makeArray(baseValue).concat(value);
              }
            } else {
              value = makeArray(value);
            }
          }

          if (mergedProperties &&
              mergedProperties.length &&
              indexOf(mergedProperties, keyName) >= 0) {
            var originalValue = this[keyName];

            value = merge(originalValue, value);
          }

          if (desc) {
            desc.set(this, keyName, value);
          } else {
            if (typeof this.setUnknownProperty === 'function' && !(keyName in this)) {
              this.setUnknownProperty(keyName, value);
            } else {
              if (Ngular.FEATURES.isEnabled('mandatory-setter')) {
                if (hasPropertyAccessors) {
                  defineProperty(this, keyName, null, value); // setup mandatory setter
                } else {
                  this[keyName] = value;
                }
              } else {
                this[keyName] = value;
              }
            }
          }
        }
      }
    }

    finishPartial(this, m);

    var length = arguments.length;

    if (length === 0) {
      this.init();
    } else if (length === 1) {
      this.init(arguments[0]);
    } else {
      // v8 bug potentially incorrectly deopts this function: https://code.google.com/p/v8/issues/detail?id=3709
      // we may want to keep this around till this ages out on mobile
      var args = new Array(length);
      for (var x = 0; x < length; x++) {
        args[x] = arguments[x];
      }
      this.init.apply(this, args);
    }

    m.proto = proto;
    finishChains(this);
    sendEvent(this, 'init');
  };