Ejemplo n.º 1
0
 url: computed(function() {
   return get(this, 'location').getURL();
 }),
Ejemplo n.º 2
0
  /**
    Iterate over each computed property for the class, passing its name
    and any associated metadata (see `metaForProperty`) to the callback.

    @static
    @method eachComputedProperty
    @param {Function} callback
    @param {Object} binding
    @private
  */
  eachComputedProperty(callback, binding) {
    let property;
    let empty = {};

    let properties = get(this, '_computedProperties');

    for (let i = 0; i < properties.length; i++) {
      property = properties[i];
      callback.call(binding || this, property.name, property.meta || empty);
    }
  }
};

function injectedPropertyAssertion() {
  assert('Injected properties are invalid', validatePropertyInjections(this));
}

if (DEBUG) {
  /**
    Provides lookup-time type validation for injected properties.
Ejemplo n.º 3
0
 addObserver(proxy, 'fullName', function() {
   last = get(proxy, 'fullName');
   count++;
 });
Ejemplo n.º 4
0
 return computed(dependentKey, function() {
   return !!get(this, dependentKey);
 });
Ejemplo n.º 5
0
 return computed(dependentKey, function() {
   return get(this, dependentKey) <= value;
 });
Ejemplo n.º 6
0
  arrangedContent: alias('content'),

  /**
    Should actually retrieve the object at the specified index from the
    content. You can override this method in subclasses to transform the
    content item to something new.

    This method will only be called if content is non-`null`.

    @method objectAtContent
    @param {Number} idx The index to retrieve.
    @return {Object} the value or undefined if none found
    @public
  */
  objectAtContent(idx) {
    return objectAt(get(this, 'arrangedContent'), idx);
  },

  /**
    Should actually replace the specified objects on the content array.
    You can override this method in subclasses to transform the content item
    into something new.

    This method will only be called if content is non-`null`.

    @method replaceContent
    @param {Number} idx The starting index
    @param {Number} amt The number of items to remove from the content.
    @param {Array} objects Optional array of objects to insert or null if no
      objects.
    @return {void}
Ejemplo n.º 7
0
        playMusic(track) {
          // ...
        }
      }
    });
    ```

    @method send
    @param {String} actionName The action to trigger
    @param {*} context a context to send with the action
    @public
  */
  send(actionName, ...args) {
    if (this.actions && this.actions[actionName]) {
      let shouldBubble = this.actions[actionName].apply(this, args) === true;
      if (!shouldBubble) { return; }
    }

    let target = get(this, 'target');
    if (target) {
      assert(
        `The \`target\` for ${this} (${target}) does not have a \`send\` method`,
        typeof target.send === 'function'
      );
      target.send(...arguments);
    }
  }
});

export default ActionHandler;
function priorityComparator(todoA, todoB) {
  let pa = parseInt(get(todoA, 'priority'), 10);
  let pb = parseInt(get(todoB, 'priority'), 10);

  return pa - pb;
}
function evenPriorities(todo) {
  let p = parseInt(get(todo, 'priority'), 10);

  return p % 2 === 0;
}
Ejemplo n.º 10
0
 run(() => {
   set(toObject, 'value', 'change');
   equal(get(fromObject, 'value'), 'start');
 });
Ejemplo n.º 11
0
 observer: emberObserver('value1', 'value2', function() {
   equal(get(this, 'value1'), 'CHANGED', 'value1 when observer fires');
   equal(get(this, 'value2'), 'CHANGED', 'value2 when observer fires');
   this.callCount++;
 })
Ejemplo n.º 12
0
QUnit.test('binding should have synced on connect', function() {
  equal(get(toObject, 'value'), 'start', 'toObject.value should match fromObject.value');
});
Ejemplo n.º 13
0
 run(function() {
   set(first, 'output', 'change');
   equal('change', get(first, 'output'), 'first.output');
   ok('change' !== get(third, 'input'), 'third.input');
 });
Ejemplo n.º 14
0
 inputDidChange: emberObserver('input', function() {
   set(this, 'output', get(this, 'input'));
 })
Ejemplo n.º 15
0
 get(key) {
   return new UnboundReference(get(this.inner, key));
 }
 mapped: map('array.@each.v', (item) => get(item, 'v').toUpperCase())
Ejemplo n.º 17
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 {Object}
  */
  setup(addedEvents, _rootElement) {
    let events = (this._finalEvents = assign({}, get(this, 'events'), addedEvents));

    if (_rootElement !== undefined && _rootElement !== null) {
      set(this, 'rootElement', _rootElement);
    }

    let rootElementSelector = get(this, 'rootElement');
    let rootElement;
    if (jQueryDisabled) {
      if (typeof rootElementSelector !== 'string') {
        rootElement = rootElementSelector;
      } else {
        rootElement = document.querySelector(rootElementSelector);
      }

      assert(
 filtered: filter('array',  (item, index, array) => index === get(array, 'length') - 2)
Ejemplo n.º 19
0
 length: computed(function() {
   let arrangedContent = get(this, 'arrangedContent');
   return arrangedContent ? get(arrangedContent, 'length') : 0;
   // No dependencies since Enumerable notifies length of change
 }),
Ejemplo n.º 20
0
    want to reuse an existing array without having to recreate it.

    ```javascript
    let colors = ['red', 'green', 'blue'];

    colors.length;  // 3
    colors.clear(); // []
    colors.length;  // 0
    ```

    @method clear
    @return {Ember.Array} An empty Array.
    @public
  */
  clear() {
    let len = get(this, 'length');
    if (len === 0) {
      return this;
    }

    this.replace(0, len, EMPTY);
    return this;
  },

  /**
    This will use the primitive `replace()` method to insert an object at the
    specified index.

    ```javascript
    let colors = ['red', 'green', 'blue'];
Ejemplo n.º 21
0
 return computed(dependentKey, function() {
   return isNone(get(this, dependentKey));
 });
      this.triggerAction({
        action: 'save'
      }); // Sends the `save` action, along with a reference to `this`,
          // to the current controller
    }
  });
  ```

  @method triggerAction
  @param opts {Object} (optional, with the optional keys action, target and/or actionContext)
  @return {Boolean} true if the action was sent successfully and did not return false
  @private
  */
  triggerAction(opts = {}) {
    let { action, target, actionContext } = opts;
    action = action || get(this, 'action');
    target = target || getTarget(this);

    if (actionContext === undefined) {
      actionContext = get(this, 'actionContextObject') || this;
    }

    if (target && action) {
      let ret;

      if (target.send) {
        ret = target.send(...[action].concat(actionContext));
      } else {
        assert(
          `The action '${action}' did not exist on ${target}`,
          typeof target[action] === 'function'
Ejemplo n.º 23
0
 return computed(dependentKey, function() {
   let value = get(this, dependentKey);
   return regexp.test(value);
 });
Ejemplo n.º 24
0
    return this.mutate !== EnumerableTests.prototype.mutate;
  }),

  /*
    Invoked to actually run the test - overridden by mixins
  */
  run() {},

  /*
    Creates a new observer object for testing.  You can add this object as an
    observer on an array and it will record results anytime it is invoked.
    After running the test, call the validate() method on the observer to
    validate the results.
  */
  newObserver(obj) {
    let ret = get(this, 'observerClass').create();
    if (arguments.length > 0) {
      ret.observeBefore.apply(ret, arguments);
    }

    if (arguments.length > 0) {
      ret.observe.apply(ret, arguments);
    }

    return ret;
  },

  observerClass: ObserverClass
});

import anyTests         from './enumerable/any';
Ejemplo n.º 25
0
 return computed(`${dependentKey}.length`, function() {
   return isEmpty(get(this, dependentKey));
 });
Ejemplo n.º 26
0
    Format:
      type: {Object} The wrapped type.
        The wrapped type has the following format:
          name: {String} The name of the type.
          count: {Integer} The number of records available.
          columns: {Columns} An array of columns to describe the record.
          object: {Class} The actual Model type class.
      release: {Function} The function to remove observers.
  */
  wrapModelType(klass, name) {
    let records = this.getRecords(klass, name);
    let typeToSend;

    typeToSend = {
      name,
      count: get(records, 'length'),
      columns: this.columnsForType(klass),
      object: klass
    };

    return typeToSend;
  },


  /**
    Fetches all models defined in the application.

    @private
    @method getModelTypes
    @return {Array} Array of model types.
  */
Ejemplo n.º 27
0
 return this.visit('/').then(() => {
   this.transitionTo('constructor', { queryParams: { foo: '999' } });
   let controller = this.getController('constructor');
   assert.equal(get(controller, 'foo'), '999');
 });
Ejemplo n.º 28
0
  },

  /**
    @private
    @since 1.12.0
    @method runInstanceInitializers
  */
  runInstanceInitializers(instance) {
    this._runInitializer('instanceInitializers', (name, initializer) => {
      assert(`No instance initializer named '${name}'`, !!initializer);
      initializer.initialize(instance);
    });
  },

  _runInitializer(bucketName, cb) {
    let initializersByName = get(this.constructor, bucketName);
    let initializers = props(initializersByName);
    let graph = new DAG();
    let initializer;

    for (let i = 0; i < initializers.length; i++) {
      initializer = initializersByName[initializers[i]];
      graph.add(initializer.name, initializer, initializer.before, initializer.after);
    }

    graph.topsort(cb);
  }
});

Engine.reopenClass({
  initializers: Object.create(null),
Ejemplo n.º 29
0
    ['@test should transition between watched and unwatched strategies'](assert) {
      let content = { foo: 'foo' };
      let proxy = ObjectProxy.create({ content: content });
      let count = 0;

      function observer() {
        count++;
      }

      assert.equal(get(proxy, 'foo'), 'foo');

      set(content, 'foo', 'bar');

      assert.equal(get(proxy, 'foo'), 'bar');

      set(proxy, 'foo', 'foo');

      assert.equal(get(content, 'foo'), 'foo');
      assert.equal(get(proxy, 'foo'), 'foo');

      addObserver(proxy, 'foo', observer);

      assert.equal(count, 0);
      assert.equal(get(proxy, 'foo'), 'foo');

      set(content, 'foo', 'bar');

      assert.equal(count, 1);
      assert.equal(get(proxy, 'foo'), 'bar');

      set(proxy, 'foo', 'foo');

      assert.equal(count, 2);
      assert.equal(get(content, 'foo'), 'foo');
      assert.equal(get(proxy, 'foo'), 'foo');

      removeObserver(proxy, 'foo', observer);

      set(content, 'foo', 'bar');

      assert.equal(get(proxy, 'foo'), 'bar');

      set(proxy, 'foo', 'foo');

      assert.equal(get(content, 'foo'), 'foo');
      assert.equal(get(proxy, 'foo'), 'foo');
    }
Ejemplo n.º 30
0
    routerMicrolib.triggerEvent = triggerEvent.bind(this);

    routerMicrolib._triggerWillChangeContext = K;
    routerMicrolib._triggerWillLeave = K;

    let dslCallbacks = this.constructor.dslCallbacks || [K];
    let dsl = this._buildDSL();

    dsl.route('application', { path: '/', resetNamespace: true, overrideNameAssertion: true }, function() {
      for (let i = 0; i < dslCallbacks.length; i++) {
        dslCallbacks[i].call(this);
      }
    });

    if (DEBUG) {
      if (get(this, 'namespace.LOG_TRANSITIONS_INTERNAL')) {
        routerMicrolib.log = Logger.debug;
      }
    }

    routerMicrolib.map(dsl.generate());
  },

  _buildDSL() {
    let moduleBasedResolver = this._hasModuleBasedResolver();
    let options = {
      enableLoadingSubstates: !!moduleBasedResolver
    };

    let owner = getOwner(this);
    let router = this;