language stringclasses 1 value | owner stringlengths 2 15 | repo stringlengths 2 21 | sha stringlengths 45 45 | message stringlengths 7 36.3k | path stringlengths 1 199 | patch stringlengths 15 102k | is_multipart bool 2 classes |
|---|---|---|---|---|---|---|---|
Other | emberjs | ember.js | 334b3df0aff2038ceda0293fecebc1ee16cc8d54.json | Implement Ember.Helper API | packages/ember-htmlbars/tests/compat/handlebars_get_test.js | @@ -3,6 +3,7 @@ import EmberView from "ember-views/views/view";
import handlebarsGet from "ember-htmlbars/compat/handlebars-get";
import { Registry } from "ember-runtime/system/container";
import { runAppend, runDestroy } from "ember-runtime/tests/utils";
+import HandlebarsCompatibleHelper from "ember-htmlbars/compat/helper";
import EmberHandlebars from "ember-htmlbars/compat";
@@ -17,7 +18,6 @@ QUnit.module("ember-htmlbars: compat - Ember.Handlebars.get", {
registry = new Registry();
container = registry.container();
registry.optionsForType('template', { instantiate: false });
- registry.optionsForType('helper', { instantiate: false });
registry.register('view:toplevel', EmberView.extend());
},
@@ -34,13 +34,13 @@ QUnit.module("ember-htmlbars: compat - Ember.Handlebars.get", {
QUnit.test('it can lookup a path from the current context', function() {
expect(1);
- registry.register('helper:handlebars-get', function(path, options) {
+ registry.register('helper:handlebars-get', new HandlebarsCompatibleHelper(function(path, options) {
var context = options.contexts && options.contexts[0] || this;
ignoreDeprecation(function() {
equal(handlebarsGet(context, path, options), 'bar');
});
- });
+ }));
view = EmberView.create({
container: container,
@@ -56,13 +56,13 @@ QUnit.test('it can lookup a path from the current context', function() {
QUnit.test('it can lookup a path from the current keywords', function() {
expect(1);
- registry.register('helper:handlebars-get', function(path, options) {
+ registry.register('helper:handlebars-get', new HandlebarsCompatibleHelper(function(path, options) {
var context = options.contexts && options.contexts[0] || this;
ignoreDeprecation(function() {
equal(handlebarsGet(context, path, options), 'bar');
});
- });
+ }));
view = EmberView.create({
container: container,
@@ -80,13 +80,13 @@ QUnit.test('it can lookup a path from globals', function() {
lookup.Blammo = { foo: 'blah' };
- registry.register('helper:handlebars-get', function(path, options) {
+ registry.register('helper:handlebars-get', new HandlebarsCompatibleHelper(function(path, options) {
var context = options.contexts && options.contexts[0] || this;
ignoreDeprecation(function() {
equal(handlebarsGet(context, path, options), lookup.Blammo.foo);
});
- });
+ }));
view = EmberView.create({
container: container,
@@ -100,13 +100,13 @@ QUnit.test('it can lookup a path from globals', function() {
QUnit.test('it raises a deprecation warning on use', function() {
expect(1);
- registry.register('helper:handlebars-get', function(path, options) {
+ registry.register('helper:handlebars-get', new HandlebarsCompatibleHelper(function(path, options) {
var context = options.contexts && options.contexts[0] || this;
expectDeprecation(function() {
handlebarsGet(context, path, options);
}, 'Usage of Ember.Handlebars.get is deprecated, use a Component or Ember.Handlebars.makeBoundHelper instead.');
- });
+ }));
view = EmberView.create({
container: container, | true |
Other | emberjs | ember.js | 334b3df0aff2038ceda0293fecebc1ee16cc8d54.json | Implement Ember.Helper API | packages/ember-htmlbars/tests/compat/helper_test.js | @@ -11,6 +11,7 @@ import compile from "ember-template-compiler/system/compile";
import { runAppend, runDestroy } from "ember-runtime/tests/utils";
import Registry from "container/registry";
import ComponentLookup from 'ember-views/component_lookup';
+import HandlebarsCompatibleHelper from "ember-htmlbars/compat/helper";
var view, registry, container;
@@ -21,7 +22,6 @@ QUnit.module('ember-htmlbars: compat - Handlebars compatible helpers', {
registry.optionsForType('component', { singleton: false });
registry.optionsForType('view', { singleton: false });
registry.optionsForType('template', { instantiate: false });
- registry.optionsForType('helper', { instantiate: false });
registry.register('component-lookup:main', ComponentLookup);
},
teardown() {
@@ -102,9 +102,9 @@ QUnit.test('has the correct options.data.view within a components layout', funct
}));
registry.register('template:components/foo-bar', compile('{{my-thing}}'));
- registry.register('helper:my-thing', function(options) {
+ registry.register('helper:my-thing', new HandlebarsCompatibleHelper(function(options) {
equal(options.data.view, component, 'passed in view should match the current component');
- });
+ }));
view = EmberView.create({
container, | true |
Other | emberjs | ember.js | 334b3df0aff2038ceda0293fecebc1ee16cc8d54.json | Implement Ember.Helper API | packages/ember-htmlbars/tests/compat/make-view-helper_test.js | @@ -11,7 +11,6 @@ QUnit.module('ember-htmlbars: compat - makeViewHelper compat', {
setup() {
registry = new Registry();
container = registry.container();
- registry.optionsForType('helper', { instantiate: false });
},
teardown() { | true |
Other | emberjs | ember.js | 334b3df0aff2038ceda0293fecebc1ee16cc8d54.json | Implement Ember.Helper API | packages/ember-htmlbars/tests/helpers/custom_helper_test.js | @@ -0,0 +1,360 @@
+import Component from "ember-views/views/component";
+import Helper from "ember-htmlbars/helper";
+import compile from "ember-template-compiler/system/compile";
+import { runAppend, runDestroy } from "ember-runtime/tests/utils";
+import Registry from "container/registry";
+import run from "ember-metal/run_loop";
+import ComponentLookup from "ember-views/component_lookup";
+
+let registry, container, component;
+
+QUnit.module('ember-htmlbars: custom app helpers', {
+ setup() {
+ registry = new Registry();
+ registry.optionsForType('template', { instantiate: false });
+ registry.optionsForType('helper', { singleton: false });
+ container = registry.container();
+ },
+
+ teardown() {
+ runDestroy(component);
+ runDestroy(container);
+ registry = container = component = null;
+ }
+});
+
+QUnit.test('dashed shorthand helper is resolved from container', function() {
+ var HelloWorld = Helper.helper(function() {
+ return 'hello world';
+ });
+ registry.register('helper:hello-world', HelloWorld);
+ component = Component.extend({
+ container,
+ layout: compile('{{hello-world}}')
+ }).create();
+
+ runAppend(component);
+ equal(component.$().text(), 'hello world');
+});
+
+QUnit.test('dashed helper is resolved from container', function() {
+ var HelloWorld = Helper.extend({
+ compute() {
+ return 'hello world';
+ }
+ });
+ registry.register('helper:hello-world', HelloWorld);
+ component = Component.extend({
+ container,
+ layout: compile('{{hello-world}}')
+ }).create();
+
+ runAppend(component);
+ equal(component.$().text(), 'hello world');
+});
+
+QUnit.test('dashed helper can recompute a new value', function() {
+ var destroyCount = 0;
+ var count = 0;
+ var helper;
+ var HelloWorld = Helper.extend({
+ init() {
+ this._super(...arguments);
+ helper = this;
+ },
+ compute() {
+ return ++count;
+ },
+ destroy() {
+ destroyCount++;
+ this._super();
+ }
+ });
+ registry.register('helper:hello-world', HelloWorld);
+ component = Component.extend({
+ container,
+ layout: compile('{{hello-world}}')
+ }).create();
+
+ runAppend(component);
+ equal(component.$().text(), '1');
+ run(function() {
+ helper.recompute();
+ });
+ equal(component.$().text(), '2');
+ equal(destroyCount, 0, 'destroy is not called on recomputation');
+});
+
+QUnit.test('dashed shorthand helper is called for param changes', function() {
+ var count = 0;
+ var HelloWorld = Helper.helper(function() {
+ return ++count;
+ });
+ registry.register('helper:hello-world', HelloWorld);
+ component = Component.extend({
+ container,
+ name: 'bob',
+ layout: compile('{{hello-world name}}')
+ }).create();
+
+ runAppend(component);
+ equal(component.$().text(), '1');
+ run(function() {
+ component.set('name', 'sal');
+ });
+ equal(component.$().text(), '2');
+});
+
+QUnit.test('dashed helper compute is called for param changes', function() {
+ var count = 0;
+ var createCount = 0;
+ var HelloWorld = Helper.extend({
+ init() {
+ this._super(...arguments);
+ // FIXME: Ideally, the helper instance does not need to be recreated
+ // for change of params.
+ createCount++;
+ },
+ compute() {
+ return ++count;
+ }
+ });
+ registry.register('helper:hello-world', HelloWorld);
+ component = Component.extend({
+ container,
+ name: 'bob',
+ layout: compile('{{hello-world name}}')
+ }).create();
+
+ runAppend(component);
+ equal(component.$().text(), '1');
+ run(function() {
+ component.set('name', 'sal');
+ });
+ equal(component.$().text(), '2');
+ equal(createCount, 1, 'helper is only created once');
+});
+
+QUnit.test('dashed shorthand helper receives params, hash', function() {
+ var params, hash;
+ var HelloWorld = Helper.helper(function(_params, _hash) {
+ params = _params;
+ hash = _hash;
+ });
+ registry.register('helper:hello-world', HelloWorld);
+ component = Component.extend({
+ container,
+ name: 'bob',
+ layout: compile('{{hello-world name "rich" last="sam"}}')
+ }).create();
+
+ runAppend(component);
+
+ equal(params[0], 'bob', 'first argument is bob');
+ equal(params[1], 'rich', 'second argument is rich');
+ equal(hash.last, 'sam', 'hash.last argument is sam');
+});
+
+QUnit.test('dashed helper receives params, hash', function() {
+ var params, hash;
+ var HelloWorld = Helper.extend({
+ compute(_params, _hash) {
+ params = _params;
+ hash = _hash;
+ }
+ });
+ registry.register('helper:hello-world', HelloWorld);
+ component = Component.extend({
+ container,
+ name: 'bob',
+ layout: compile('{{hello-world name "rich" last="sam"}}')
+ }).create();
+
+ runAppend(component);
+
+ equal(params[0], 'bob', 'first argument is bob');
+ equal(params[1], 'rich', 'second argument is rich');
+ equal(hash.last, 'sam', 'hash.last argument is sam');
+});
+
+QUnit.test('dashed helper usable in subexpressions', function() {
+ var JoinWords = Helper.extend({
+ compute(params) {
+ return params.join(' ');
+ }
+ });
+ registry.register('helper:join-words', JoinWords);
+ component = Component.extend({
+ container,
+ layout: compile(
+ `{{join-words "Who"
+ (join-words "overcomes" "by")
+ "force"
+ (join-words (join-words "hath overcome but" "half"))
+ (join-words "his" (join-words "foe"))}}`)
+ }).create();
+
+ runAppend(component);
+
+ equal(component.$().text(),
+ 'Who overcomes by force hath overcome but half his foe');
+});
+
+QUnit.test('dashed helper not usable with a block', function() {
+ var SomeHelper = Helper.helper(function() {});
+ registry.register('helper:some-helper', SomeHelper);
+ component = Component.extend({
+ container,
+ layout: compile(`{{#some-helper}}{{/some-helper}}`)
+ }).create();
+
+ expectAssertion(function() {
+ runAppend(component);
+ }, /Helpers may not be used in the block form/);
+});
+
+QUnit.test('dashed helper is torn down', function() {
+ var destroyCalled = 0;
+ var SomeHelper = Helper.extend({
+ destroy() {
+ destroyCalled++;
+ this._super.apply(this, arguments);
+ },
+ compute() {
+ return 'must define a compute';
+ }
+ });
+ registry.register('helper:some-helper', SomeHelper);
+ component = Component.extend({
+ container,
+ layout: compile(`{{some-helper}}`)
+ }).create();
+
+ runAppend(component);
+ runDestroy(component);
+
+ equal(destroyCalled, 1, 'destroy called once');
+});
+
+QUnit.test('dashed helper used in subexpression can recompute', function() {
+ var helper;
+ var phrase = 'overcomes by';
+ var DynamicSegment = Helper.extend({
+ init() {
+ this._super(...arguments);
+ helper = this;
+ },
+ compute() {
+ return phrase;
+ }
+ });
+ var JoinWords = Helper.extend({
+ compute(params) {
+ return params.join(' ');
+ }
+ });
+ registry.register('helper:dynamic-segment', DynamicSegment);
+ registry.register('helper:join-words', JoinWords);
+ component = Component.extend({
+ container,
+ layout: compile(
+ `{{join-words "Who"
+ (dynamic-segment)
+ "force"
+ (join-words (join-words "hath overcome but" "half"))
+ (join-words "his" (join-words "foe"))}}`)
+ }).create();
+
+ runAppend(component);
+
+ equal(component.$().text(),
+ 'Who overcomes by force hath overcome but half his foe');
+
+ phrase = 'believes his';
+ Ember.run(function() {
+ helper.recompute();
+ });
+
+ equal(component.$().text(),
+ 'Who believes his force hath overcome but half his foe');
+});
+
+QUnit.test('dashed helper used in subexpression can recompute component', function() {
+ var helper;
+ var phrase = 'overcomes by';
+ var DynamicSegment = Helper.extend({
+ init() {
+ this._super(...arguments);
+ helper = this;
+ },
+ compute() {
+ return phrase;
+ }
+ });
+ var JoinWords = Helper.extend({
+ compute(params) {
+ return params.join(' ');
+ }
+ });
+ registry.register('component-lookup:main', ComponentLookup);
+ registry.register('component:some-component', Ember.Component.extend({
+ layout: compile('{{first}} {{second}} {{third}} {{fourth}} {{fifth}}')
+ }));
+ registry.register('helper:dynamic-segment', DynamicSegment);
+ registry.register('helper:join-words', JoinWords);
+ component = Component.extend({
+ container,
+ layout: compile(
+ `{{some-component first="Who"
+ second=(dynamic-segment)
+ third="force"
+ fourth=(join-words (join-words "hath overcome but" "half"))
+ fifth=(join-words "his" (join-words "foe"))}}`)
+ }).create();
+
+ runAppend(component);
+
+ equal(component.$().text(),
+ 'Who overcomes by force hath overcome but half his foe');
+
+ phrase = 'believes his';
+ Ember.run(function() {
+ helper.recompute();
+ });
+
+ equal(component.$().text(),
+ 'Who believes his force hath overcome but half his foe');
+});
+
+QUnit.test('dashed helper used in subexpression is destroyed', function() {
+ var destroyCount = 0;
+ var DynamicSegment = Helper.extend({
+ phrase: 'overcomes by',
+ compute() {
+ return this.phrase;
+ },
+ destroy() {
+ destroyCount++;
+ this._super(...arguments);
+ }
+ });
+ var JoinWords = Helper.helper(function(params) {
+ return params.join(' ');
+ });
+ registry.register('helper:dynamic-segment', DynamicSegment);
+ registry.register('helper:join-words', JoinWords);
+ component = Component.extend({
+ container,
+ layout: compile(
+ `{{join-words "Who"
+ (dynamic-segment)
+ "force"
+ (join-words (join-words "hath overcome but" "half"))
+ (join-words "his" (join-words "foe"))}}`)
+ }).create();
+
+ runAppend(component);
+ runDestroy(component);
+
+ equal(destroyCount, 1, 'destroy is called after a view is destroyed');
+}); | true |
Other | emberjs | ember.js | 334b3df0aff2038ceda0293fecebc1ee16cc8d54.json | Implement Ember.Helper API | packages/ember-htmlbars/tests/helpers/unbound_test.js | @@ -482,7 +482,6 @@ QUnit.module("ember-htmlbars: {{#unbound}} helper -- Container Lookup", {
Ember.lookup = lookup = { Ember: Ember };
registry = new Registry();
container = registry.container();
- registry.optionsForType('helper', { instantiate: false });
},
teardown() { | true |
Other | emberjs | ember.js | 334b3df0aff2038ceda0293fecebc1ee16cc8d54.json | Implement Ember.Helper API | packages/ember-htmlbars/tests/helpers/view_test.js | @@ -49,7 +49,6 @@ QUnit.module("ember-htmlbars: {{#view}} helper", {
registry = new Registry();
container = registry.container();
registry.optionsForType('template', { instantiate: false });
- registry.optionsForType('helper', { instantiate: false });
registry.register('view:toplevel', EmberView.extend());
registry.register('component-lookup:main', ComponentLookup);
}, | true |
Other | emberjs | ember.js | 334b3df0aff2038ceda0293fecebc1ee16cc8d54.json | Implement Ember.Helper API | packages/ember-htmlbars/tests/integration/block_params_test.js | @@ -22,7 +22,6 @@ QUnit.module("ember-htmlbars: block params", {
registry.optionsForType('component', { singleton: false });
registry.optionsForType('view', { singleton: false });
registry.optionsForType('template', { instantiate: false });
- registry.optionsForType('helper', { instantiate: false });
registry.register('component-lookup:main', ComponentLookup);
},
| true |
Other | emberjs | ember.js | 334b3df0aff2038ceda0293fecebc1ee16cc8d54.json | Implement Ember.Helper API | packages/ember-htmlbars/tests/integration/component_element_id_test.js | @@ -14,7 +14,6 @@ QUnit.module('ember-htmlbars: component elementId', {
registry.optionsForType('component', { singleton: false });
registry.optionsForType('view', { singleton: false });
registry.optionsForType('template', { instantiate: false });
- registry.optionsForType('helper', { instantiate: false });
registry.register('component-lookup:main', ComponentLookup);
},
| true |
Other | emberjs | ember.js | 334b3df0aff2038ceda0293fecebc1ee16cc8d54.json | Implement Ember.Helper API | packages/ember-htmlbars/tests/integration/component_invocation_test.js | @@ -17,7 +17,6 @@ function commonSetup() {
registry.optionsForType('component', { singleton: false });
registry.optionsForType('view', { singleton: false });
registry.optionsForType('template', { instantiate: false });
- registry.optionsForType('helper', { instantiate: false });
registry.register('component-lookup:main', ComponentLookup);
}
| true |
Other | emberjs | ember.js | 334b3df0aff2038ceda0293fecebc1ee16cc8d54.json | Implement Ember.Helper API | packages/ember-htmlbars/tests/integration/component_lifecycle_test.js | @@ -17,7 +17,6 @@ QUnit.module('component - lifecycle hooks', {
registry.optionsForType('component', { singleton: false });
registry.optionsForType('view', { singleton: false });
registry.optionsForType('template', { instantiate: false });
- registry.optionsForType('helper', { instantiate: false });
registry.register('component-lookup:main', ComponentLookup);
hooks = []; | true |
Other | emberjs | ember.js | 334b3df0aff2038ceda0293fecebc1ee16cc8d54.json | Implement Ember.Helper API | packages/ember-htmlbars/tests/integration/mutable_binding_test.js | @@ -17,7 +17,6 @@ QUnit.module('component - mutable bindings', {
registry.optionsForType('component', { singleton: false });
registry.optionsForType('view', { singleton: false });
registry.optionsForType('template', { instantiate: false });
- registry.optionsForType('helper', { instantiate: false });
registry.register('component-lookup:main', ComponentLookup);
},
| true |
Other | emberjs | ember.js | 334b3df0aff2038ceda0293fecebc1ee16cc8d54.json | Implement Ember.Helper API | packages/ember-htmlbars/tests/integration/void-element-component-test.js | @@ -14,7 +14,6 @@ QUnit.module('ember-htmlbars: components for void elements', {
registry.optionsForType('component', { singleton: false });
registry.optionsForType('view', { singleton: false });
registry.optionsForType('template', { instantiate: false });
- registry.optionsForType('helper', { instantiate: false });
registry.register('component-lookup:main', ComponentLookup);
},
| true |
Other | emberjs | ember.js | 334b3df0aff2038ceda0293fecebc1ee16cc8d54.json | Implement Ember.Helper API | packages/ember-htmlbars/tests/system/lookup-helper_test.js | @@ -1,7 +1,7 @@
import lookupHelper, { findHelper } from "ember-htmlbars/system/lookup-helper";
import ComponentLookup from "ember-views/component_lookup";
import Registry from "container/registry";
-import Component from "ember-views/views/component";
+import Helper from "ember-htmlbars/helper";
function generateEnv(helpers, container) {
return {
@@ -15,7 +15,6 @@ function generateContainer() {
var registry = new Registry();
var container = registry.container();
- registry.optionsForType('helper', { instantiate: false });
registry.register('component-lookup:main', ComponentLookup);
return container;
@@ -64,16 +63,15 @@ QUnit.test('does a lookup in the container if the name contains a dash (and help
container: container
};
- function someName() {}
- someName.isHTMLBars = true;
+ var someName = Helper.extend();
view.container._registry.register('helper:some-name', someName);
var actual = lookupHelper('some-name', view, env);
- equal(actual, someName, 'does not wrap provided function if `isHTMLBars` is truthy');
+ ok(someName.detect(actual), 'helper is an instance of the helper class');
});
-QUnit.test('wraps helper from container in a Handlebars compat helper', function() {
+QUnit.test('looks up a shorthand helper in the container', function() {
expect(2);
var container = generateContainer();
var env = generateEnv(null, container);
@@ -85,50 +83,29 @@ QUnit.test('wraps helper from container in a Handlebars compat helper', function
function someName() {
called = true;
}
- view.container._registry.register('helper:some-name', someName);
+ view.container._registry.register('helper:some-name', Helper.helper(someName));
var actual = lookupHelper('some-name', view, env);
- ok(actual.isHTMLBars, 'wraps provided helper in an HTMLBars compatible helper');
+ ok(actual.isHelperInstance, 'is a helper');
- var fakeParams = [];
- var fakeHash = {};
- var fakeOptions = {
- morph: { update() { } },
- template: {},
- inverse: {}
- };
- var fakeEnv = { };
- var fakeScope = { };
- actual.helperFunction(fakeParams, fakeHash, fakeOptions, fakeEnv, fakeScope);
+ actual.compute([], {});
ok(called, 'HTMLBars compatible wrapper is wraping the provided function');
});
-QUnit.test('asserts if component-lookup:main cannot be found', function() {
+QUnit.test('fails with a useful error when resolving a function', function() {
+ expect(1);
var container = generateContainer();
var env = generateEnv(null, container);
var view = {
container: container
};
- view.container._registry.unregister('component-lookup:main');
+ function someName() {}
+ view.container._registry.register('helper:some-name', someName);
expectAssertion(function() {
lookupHelper('some-name', view, env);
- }, 'Could not find \'component-lookup:main\' on the provided container, which is necessary for performing component lookups');
-});
-
-QUnit.test('registers a helper in the container if component is found', function() {
- var container = generateContainer();
- var env = generateEnv(null, container);
- var view = {
- container: container
- };
-
- view.container._registry.register('component:some-name', Component);
-
- lookupHelper('some-name', view, env);
-
- ok(view.container.lookup('helper:some-name'), 'new helper was registered');
+ }, /The factory for "some-name" is not an Ember helper/);
}); | true |
Other | emberjs | ember.js | 334b3df0aff2038ceda0293fecebc1ee16cc8d54.json | Implement Ember.Helper API | packages/ember-htmlbars/tests/system/make_bound_helper_test.js | @@ -21,7 +21,6 @@ QUnit.module("ember-htmlbars: makeBoundHelper", {
setup() {
registry = new Registry();
container = registry.container();
- registry.optionsForType('helper', { instantiate: false });
},
teardown() {
@@ -192,7 +191,7 @@ QUnit.test("bound helpers should not be invoked with blocks", function() {
expectAssertion(function() {
runAppend(view);
- }, /makeBoundHelper generated helpers do not support use with blocks/i);
+ }, /Helpers may not be used in the block form/);
});
QUnit.test("shouldn't treat raw numbers as bound paths", function() { | true |
Other | emberjs | ember.js | 334b3df0aff2038ceda0293fecebc1ee16cc8d54.json | Implement Ember.Helper API | packages/ember-htmlbars/tests/system/make_view_helper_test.js | @@ -10,7 +10,6 @@ QUnit.module("ember-htmlbars: makeViewHelper", {
setup() {
registry = new Registry();
container = registry.container();
- registry.optionsForType('helper', { instantiate: false });
},
teardown() {
runDestroy(view); | true |
Other | emberjs | ember.js | 334b3df0aff2038ceda0293fecebc1ee16cc8d54.json | Implement Ember.Helper API | packages/ember-views/lib/component_lookup.js | @@ -1,13 +1,12 @@
import Ember from 'ember-metal/core';
import EmberObject from "ember-runtime/system/object";
-import { ISNT_HELPER_CACHE } from "ember-htmlbars/system/lookup-helper";
+import { CONTAINS_DASH_CACHE } from "ember-htmlbars/system/lookup-helper";
export default EmberObject.extend({
invalidName(name) {
- var invalidName = ISNT_HELPER_CACHE.get(name);
-
- if (invalidName) {
+ if (!CONTAINS_DASH_CACHE.get(name)) {
Ember.assert(`You cannot use '${name}' as a component name. Component names must contain a hyphen.`);
+ return true;
}
},
| true |
Other | emberjs | ember.js | 334b3df0aff2038ceda0293fecebc1ee16cc8d54.json | Implement Ember.Helper API | packages/ember/tests/helpers/helper_registration_test.js | @@ -1,6 +1,7 @@
import "ember";
import EmberHandlebars from "ember-htmlbars/compat";
+import HandlebarsCompatibleHelper from "ember-htmlbars/compat/helper";
var compile, helpers, makeBoundHelper;
compile = EmberHandlebars.compile;
@@ -56,13 +57,13 @@ var boot = function(callback) {
};
QUnit.test("Unbound dashed helpers registered on the container can be late-invoked", function() {
+ Ember.TEMPLATES.application = compile("<div id='wrapper'>{{x-borf}} {{x-borf 'YES'}}</div>");
+ let helper = new HandlebarsCompatibleHelper(function(val) {
+ return arguments.length > 1 ? val : "BORF";
+ });
- Ember.TEMPLATES.application = compile("<div id='wrapper'>{{x-borf}} {{x-borf YES}}</div>");
-
- boot(function() {
- registry.register('helper:x-borf', function(val) {
- return arguments.length > 1 ? val : "BORF";
- });
+ boot(() => {
+ registry.register('helper:x-borf', helper);
});
equal(Ember.$('#wrapper').text(), "BORF YES", "The helper was invoked from the container");
@@ -121,3 +122,24 @@ QUnit.test("Undashed helpers registered on the container can not (presently) be
});
}, /A helper named 'omg' could not be found/);
});
+
+QUnit.test("Helpers can receive injections", function() {
+ Ember.TEMPLATES.application = compile("<div id='wrapper'>{{full-name}}</div>");
+
+ var serviceCalled = false;
+ boot(function() {
+ registry.register('service:name-builder', Ember.Service.extend({
+ build() {
+ serviceCalled = true;
+ }
+ }));
+ registry.register('helper:full-name', Ember.Helper.extend({
+ nameBuilder: Ember.inject.service('name-builder'),
+ compute() {
+ this.get('nameBuilder').build();
+ }
+ }));
+ });
+
+ ok(serviceCalled, 'service was injected, method called');
+}); | true |
Other | emberjs | ember.js | 930513b5c86007baa3e81c4d94f6ea8715a17880.json | Add special values to legacy `{{each}}`s' keyPath | packages/ember-htmlbars/lib/helpers/-legacy-each-with-controller.js | @@ -1,6 +1,7 @@
import { get } from "ember-metal/property_get";
import { forEach } from "ember-metal/enumerable_utils";
import normalizeSelf from "ember-htmlbars/utils/normalize-self";
+import decodeEachKey from "ember-htmlbars/utils/decode-each-key";
export default function legacyEachWithControllerHelper(params, hash, blocks) {
var list = params[0];
@@ -21,7 +22,7 @@ export default function legacyEachWithControllerHelper(params, hash, blocks) {
self = bindController(self, true);
}
- var key = keyPath ? get(item, keyPath) : String(i);
+ var key = decodeEachKey(item, keyPath, i);
blocks.template.yieldItem(key, [item, i], self);
});
} | true |
Other | emberjs | ember.js | 930513b5c86007baa3e81c4d94f6ea8715a17880.json | Add special values to legacy `{{each}}`s' keyPath | packages/ember-htmlbars/lib/helpers/-legacy-each-with-keyword.js | @@ -1,6 +1,6 @@
-import { get } from "ember-metal/property_get";
import { forEach } from "ember-metal/enumerable_utils";
import shouldDisplay from "ember-views/streams/should_display";
+import decodeEachKey from "ember-htmlbars/utils/decode-each-key";
export default function legacyEachWithKeywordHelper(params, hash, blocks) {
var list = params[0];
@@ -14,7 +14,7 @@ export default function legacyEachWithKeywordHelper(params, hash, blocks) {
self = bindKeyword(self, legacyKeyword, item);
}
- var key = keyPath ? get(item, keyPath) : String(i);
+ var key = decodeEachKey(item, keyPath, i);
blocks.template.yieldItem(key, [item, i], self);
});
} else if (blocks.inverse.yield) { | true |
Other | emberjs | ember.js | 930513b5c86007baa3e81c4d94f6ea8715a17880.json | Add special values to legacy `{{each}}`s' keyPath | packages/ember-htmlbars/lib/helpers/each.js | @@ -1,8 +1,7 @@
-import { get } from "ember-metal/property_get";
import { forEach } from "ember-metal/enumerable_utils";
-import { guidFor } from "ember-metal/utils";
import normalizeSelf from "ember-htmlbars/utils/normalize-self";
import shouldDisplay from "ember-views/streams/should_display";
+import decodeEachKey from "ember-htmlbars/utils/decode-each-key";
/**
The `{{#each}}` helper loops over elements in a collection. It is an extension
@@ -89,25 +88,7 @@ export default function eachHelper(params, hash, blocks) {
self = normalizeSelf(item);
}
- var key;
- switch (keyPath) {
- case '@index':
- key = i;
- break;
- case '@guid':
- key = guidFor(item);
- break;
- case '@item':
- key = item;
- break;
- default:
- key = keyPath ? get(item, keyPath) : i;
- }
-
- if (typeof key === 'number') {
- key = String(key);
- }
-
+ var key = decodeEachKey(item, keyPath, i);
blocks.template.yieldItem(key, [item, i], self);
});
} else if (blocks.inverse.yield) { | true |
Other | emberjs | ember.js | 930513b5c86007baa3e81c4d94f6ea8715a17880.json | Add special values to legacy `{{each}}`s' keyPath | packages/ember-htmlbars/lib/utils/decode-each-key.js | @@ -0,0 +1,26 @@
+import { get } from "ember-metal/property_get";
+import { guidFor } from "ember-metal/utils";
+
+export default function decodeEachKey(item, keyPath, index) {
+ var key;
+
+ switch (keyPath) {
+ case '@index':
+ key = index;
+ break;
+ case '@guid':
+ key = guidFor(item);
+ break;
+ case '@item':
+ key = item;
+ break;
+ default:
+ key = keyPath ? get(item, keyPath) : index;
+ }
+
+ if (typeof key === 'number') {
+ key = String(key);
+ }
+
+ return key;
+} | true |
Other | emberjs | ember.js | c963eed9ebebbc2075029348075e36f3cc6ba04a.json | Use model name instead of factory in data adapter | packages/ember-extension-support/lib/data_adapter.js | @@ -92,6 +92,20 @@ export default EmberObject.extend({
*/
attributeLimit: 3,
+ /**
+ * Ember Data > v1.0.0-beta.18
+ * requires string model names to be passed
+ * around instead of the actual factories.
+ *
+ * This is a stamp for the Ember Inspector
+ * to differentiate between the versions
+ * to be able to support older versions too.
+ *
+ * @public
+ * @property acceptsModelName
+ */
+ acceptsModelName: true,
+
/**
Stores all methods that clear observers.
These methods will be called on destruction.
@@ -138,7 +152,7 @@ export default EmberObject.extend({
typesToSend = modelTypes.map((type) => {
var klass = type.klass;
var wrapped = this.wrapModelType(klass, type.name);
- releaseMethods.push(this.observeModelType(klass, typesUpdated));
+ releaseMethods.push(this.observeModelType(type.name, typesUpdated));
return wrapped;
});
@@ -165,6 +179,8 @@ export default EmberObject.extend({
@public
@method watchRecords
+ @param {String} modelName The model name
+
@param {Function} recordsAdded Callback to call to add records.
Takes an array of objects containing wrapped records.
The object should have the following properties:
@@ -181,9 +197,10 @@ export default EmberObject.extend({
@return {Function} Method to call to remove all observers
*/
- watchRecords(type, recordsAdded, recordsUpdated, recordsRemoved) {
+ watchRecords(modelName, recordsAdded, recordsUpdated, recordsRemoved) {
var releaseMethods = emberA();
- var records = this.getRecords(type);
+ var klass = this._nameToClass(modelName);
+ var records = this.getRecords(klass, modelName);
var release;
var recordUpdated = function(updatedRecord) {
@@ -270,16 +287,17 @@ export default EmberObject.extend({
@private
@method observeModelType
- @param {Class} type The model type class
+ @param {String} modelName The model type name
@param {Function} typesUpdated Called when a type is modified.
@return {Function} The function to call to remove observers
*/
- observeModelType(type, typesUpdated) {
- var records = this.getRecords(type);
+ observeModelType(modelName, typesUpdated) {
+ var klass = this._nameToClass(modelName);
+ var records = this.getRecords(klass, modelName);
var onChange = () => {
- typesUpdated([this.wrapModelType(type)]);
+ typesUpdated([this.wrapModelType(klass, modelName)]);
};
var observer = {
didChange() {
@@ -303,8 +321,8 @@ export default EmberObject.extend({
@private
@method wrapModelType
- @param {Class} type A model class
- @param {String} Optional name of the class
+ @param {Class} klass A model class
+ @param {String} modelName Name of the class
@return {Object} contains the wrapped type and the function to remove observers
Format:
type: {Object} the wrapped type
@@ -315,15 +333,15 @@ export default EmberObject.extend({
object: {Class} the actual Model type class
release: {Function} The function to remove observers
*/
- wrapModelType(type, name) {
- var records = this.getRecords(type);
+ wrapModelType(klass, name) {
+ var records = this.getRecords(klass, name);
var typeToSend;
typeToSend = {
- name: name || type.toString(),
+ name,
count: get(records, 'length'),
- columns: this.columnsForType(type),
- object: type
+ columns: this.columnsForType(klass),
+ object: klass
};
@@ -378,7 +396,7 @@ export default EmberObject.extend({
for (var key in namespace) {
if (!namespace.hasOwnProperty(key)) { continue; }
// Even though we will filter again in `getModelTypes`,
- // we should not call `lookupContainer` on non-models
+ // we should not call `lookupFactory` on non-models
// (especially when `Ember.MODEL_FACTORY_INJECTIONS` is `true`)
if (!this.detect(namespace[key])) { continue; }
var name = dasherize(key); | true |
Other | emberjs | ember.js | c963eed9ebebbc2075029348075e36f3cc6ba04a.json | Use model name instead of factory in data adapter | packages/ember-extension-support/tests/data_adapter_test.js | @@ -65,6 +65,20 @@ QUnit.test("Model types added with DefaultResolver", function() {
adapter.watchModelTypes(modelTypesAdded);
});
+QUnit.test("getRecords gets a model name as second argument", function() {
+ App.Post = Model.extend();
+
+ adapter = App.__container__.lookup('data-adapter:main');
+ adapter.reopen({
+ getRecords(klass, name) {
+ equal(name, 'post');
+ return Ember.A([]);
+ }
+ });
+
+ adapter.watchModelTypes(function() { });
+});
+
QUnit.test("Model types added with custom container-debug-adapter", function() {
var PostClass = Model.extend();
var StubContainerDebugAdapter = DefaultResolver.extend({ | true |
Other | emberjs | ember.js | f1df1d43d449b9aecb6c0585520cb10602ca9dd8.json | JSDoc: Replace "Integer" type with "Number"
"Integer" is not a valid type | packages/ember-runtime/lib/mixins/array.js | @@ -205,8 +205,8 @@ export default Mixin.create(Enumerable, {
```
@method slice
- @param {Integer} beginIndex (Optional) index to begin slicing from.
- @param {Integer} endIndex (Optional) index to end the slice at (but not included).
+ @param {Number} beginIndex (Optional) index to begin slicing from.
+ @param {Number} endIndex (Optional) index to end the slice at (but not included).
@return {Array} New array with specified slice
*/
slice(beginIndex, endIndex) { | true |
Other | emberjs | ember.js | f1df1d43d449b9aecb6c0585520cb10602ca9dd8.json | JSDoc: Replace "Integer" type with "Number"
"Integer" is not a valid type | packages/ember-runtime/lib/mixins/comparable.js | @@ -32,7 +32,7 @@ export default Mixin.create({
@method compare
@param a {Object} the first object to compare
@param b {Object} the second object to compare
- @return {Integer} the result of the comparison
+ @return {Number} the result of the comparison
*/
compare: null
}); | true |
Other | emberjs | ember.js | da3003c547a09132f5744c3325804e6dae7407ef.json | JSDoc: Replace "Hash" type with "Object"
"Hash" is not a valid type | packages/ember-htmlbars/lib/helpers/bind-attr.js | @@ -124,7 +124,7 @@
@method bind-attr
@for Ember.Handlebars.helpers
@deprecated
- @param {Hash} options
+ @param {Object} options
@return {String} HTML string
*/
@@ -135,6 +135,6 @@
@for Ember.Handlebars.helpers
@deprecated
@param {Function} context
- @param {Hash} options
+ @param {Object} options
@return {String} HTML string
*/ | true |
Other | emberjs | ember.js | da3003c547a09132f5744c3325804e6dae7407ef.json | JSDoc: Replace "Hash" type with "Object"
"Hash" is not a valid type | packages/ember-htmlbars/lib/helpers/with.js | @@ -34,7 +34,7 @@ import shouldDisplay from "ember-views/streams/should_display";
@method with
@for Ember.Handlebars.helpers
- @param {Hash} options
+ @param {Object} options
@return {String} HTML string
*/
| true |
Other | emberjs | ember.js | da3003c547a09132f5744c3325804e6dae7407ef.json | JSDoc: Replace "Hash" type with "Object"
"Hash" is not a valid type | packages/ember-metal/lib/computed.js | @@ -278,7 +278,7 @@ ComputedPropertyPrototype.property = function() {
via the `metaForProperty()` function.
@method meta
- @param {Hash} meta
+ @param {Object} meta
@chainable
*/
| true |
Other | emberjs | ember.js | da3003c547a09132f5744c3325804e6dae7407ef.json | JSDoc: Replace "Hash" type with "Object"
"Hash" is not a valid type | packages/ember-metal/lib/core.js | @@ -63,7 +63,7 @@ Ember.VERSION = 'VERSION_STRING_PLACEHOLDER';
hash must be created before loading Ember.
@property ENV
- @type Hash
+ @type Object
*/
if (Ember.ENV) { | true |
Other | emberjs | ember.js | da3003c547a09132f5744c3325804e6dae7407ef.json | JSDoc: Replace "Hash" type with "Object"
"Hash" is not a valid type | packages/ember-routing/lib/system/route.js | @@ -82,7 +82,7 @@ var Route = EmberObject.extend(ActionHandler, Evented, {
@property queryParams
@for Ember.Route
- @type Hash
+ @type Object
*/
queryParams: {},
| true |
Other | emberjs | ember.js | da3003c547a09132f5744c3325804e6dae7407ef.json | JSDoc: Replace "Hash" type with "Object"
"Hash" is not a valid type | packages/ember-runtime/lib/mixins/action_handler.js | @@ -140,7 +140,7 @@ var ActionHandler = Mixin.create({
```
@property actions
- @type Hash
+ @type Object
@default null
*/
| true |
Other | emberjs | ember.js | da3003c547a09132f5744c3325804e6dae7407ef.json | JSDoc: Replace "Hash" type with "Object"
"Hash" is not a valid type | packages/ember-runtime/lib/mixins/array.js | @@ -346,7 +346,7 @@ export default Mixin.create(Enumerable, {
@method addArrayObserver
@param {Object} target The observer object.
- @param {Hash} opts Optional hash of configuration options including
+ @param {Object} opts Optional hash of configuration options including
`willChange` and `didChange` option.
@return {Ember.Array} receiver
*/
@@ -362,7 +362,7 @@ export default Mixin.create(Enumerable, {
@method removeArrayObserver
@param {Object} target The object observing the array.
- @param {Hash} opts Optional hash of configuration options including
+ @param {Object} opts Optional hash of configuration options including
`willChange` and `didChange` option.
@return {Ember.Array} receiver
*/ | true |
Other | emberjs | ember.js | da3003c547a09132f5744c3325804e6dae7407ef.json | JSDoc: Replace "Hash" type with "Object"
"Hash" is not a valid type | packages/ember-runtime/lib/mixins/enumerable.js | @@ -970,7 +970,7 @@ export default Mixin.create({
@method addEnumerableObserver
@param {Object} target
- @param {Hash} [opts]
+ @param {Object} [opts]
@return this
*/
addEnumerableObserver(target, opts) {
@@ -997,7 +997,7 @@ export default Mixin.create({
@method removeEnumerableObserver
@param {Object} target
- @param {Hash} [opts]
+ @param {Object} [opts]
@return this
*/
removeEnumerableObserver(target, opts) { | true |
Other | emberjs | ember.js | da3003c547a09132f5744c3325804e6dae7407ef.json | JSDoc: Replace "Hash" type with "Object"
"Hash" is not a valid type | packages/ember-runtime/lib/mixins/observable.js | @@ -155,7 +155,7 @@ export default Mixin.create({
@method getProperties
@param {String...|Array} list of keys to get
- @return {Hash}
+ @return {Object}
*/
getProperties(...args) {
return getProperties.apply(null, [this].concat(args));
@@ -225,7 +225,7 @@ export default Mixin.create({
```
@method setProperties
- @param {Hash} hash the hash of keys and values to set
+ @param {Object} hash the hash of keys and values to set
@return {Ember.Observable}
*/
setProperties(hash) { | true |
Other | emberjs | ember.js | da3003c547a09132f5744c3325804e6dae7407ef.json | JSDoc: Replace "Hash" type with "Object"
"Hash" is not a valid type | packages/ember-runtime/lib/mixins/target_action_support.js | @@ -107,7 +107,7 @@ var TargetActionSupport = Mixin.create({
```
@method triggerAction
- @param opts {Hash} (optional, with the optional keys action, target and/or actionContext)
+ @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
*/
triggerAction(opts) { | true |
Other | emberjs | ember.js | da3003c547a09132f5744c3325804e6dae7407ef.json | JSDoc: Replace "Hash" type with "Object"
"Hash" is not a valid type | packages/ember-runtime/lib/system/string.js | @@ -124,7 +124,7 @@ function capitalize(str) {
@property STRINGS
@for Ember
- @type Hash
+ @type Object
*/
Ember.STRINGS = {};
| true |
Other | emberjs | ember.js | da3003c547a09132f5744c3325804e6dae7407ef.json | JSDoc: Replace "Hash" type with "Object"
"Hash" is not a valid type | packages/ember-views/lib/mixins/view_child_views_support.js | @@ -74,7 +74,7 @@ var ViewChildViewsSupport = Mixin.create({
@method createChildView
@param {Class|String} viewClass
- @param {Hash} [attrs] Attributes to add
+ @param {Object} [attrs] Attributes to add
@return {Ember.View} new instance
*/
createChildView(maybeViewClass, _attrs) { | true |
Other | emberjs | ember.js | da3003c547a09132f5744c3325804e6dae7407ef.json | JSDoc: Replace "Hash" type with "Object"
"Hash" is not a valid type | packages/ember-views/lib/system/event_dispatcher.js | @@ -124,7 +124,7 @@ export default EmberObject.extend({
@private
@method setup
- @param addedEvents {Hash}
+ @param addedEvents {Object}
*/
setup(addedEvents, rootElement) {
var event; | true |
Other | emberjs | ember.js | da3003c547a09132f5744c3325804e6dae7407ef.json | JSDoc: Replace "Hash" type with "Object"
"Hash" is not a valid type | packages/ember-views/lib/views/collection_view.js | @@ -345,7 +345,7 @@ var CollectionView = ContainerView.extend(EmptyViewSupport, {
@method createChildView
@param {Class} viewClass
- @param {Hash} [attrs] Attributes to add
+ @param {Object} [attrs] Attributes to add
@return {Ember.View} new instance
*/
createChildView(_view, attrs) {
@@ -392,7 +392,7 @@ var CollectionView = ContainerView.extend(EmptyViewSupport, {
a particular parent tag to default to a child tag.
@property CONTAINER_MAP
- @type Hash
+ @type Object
@static
@final
*/ | true |
Other | emberjs | ember.js | da3003c547a09132f5744c3325804e6dae7407ef.json | JSDoc: Replace "Hash" type with "Object"
"Hash" is not a valid type | packages/ember-views/lib/views/view.js | @@ -52,7 +52,7 @@ Ember.warn("The VIEW_PRESERVES_CONTEXT flag has been removed and the functionali
@property TEMPLATES
@for Ember
- @type Hash
+ @type Object
*/
Ember.TEMPLATES = {};
@@ -1499,7 +1499,7 @@ View.notifyMutationListeners = function() {
@property views
@static
- @type Hash
+ @type Object
*/
View.views = {};
| true |
Other | emberjs | ember.js | 6f769aab58d9cad6195859d8ec1b6f66ab134fb3.json | Fix broken JSDoc references | packages/ember-htmlbars/lib/compat/make-bound-helper.js | @@ -32,7 +32,7 @@ import {
@method makeBoundHelper
@for Ember.Handlebars
- @param {Function} function
+ @param {Function} fn
@param {String} dependentKeys*
@since 1.2.0
@deprecated | true |
Other | emberjs | ember.js | 6f769aab58d9cad6195859d8ec1b6f66ab134fb3.json | Fix broken JSDoc references | packages/ember-htmlbars/lib/compat/register-bound-helper.js | @@ -114,7 +114,7 @@ var slice = [].slice;
@method registerBoundHelper
@for Ember.Handlebars
@param {String} name
- @param {Function} function
+ @param {Function} fn
@param {String} dependentKeys*
*/
export default function registerBoundHelper(name, fn) { | true |
Other | emberjs | ember.js | 6f769aab58d9cad6195859d8ec1b6f66ab134fb3.json | Fix broken JSDoc references | packages/ember-htmlbars/lib/helpers/each.js | @@ -73,9 +73,6 @@ import shouldDisplay from "ember-views/streams/should_display";
@method each
@for Ember.Handlebars.helpers
- @param [name] {String} name for item (used with `as`)
- @param [path] {String} path
- @param [options] {Object} Handlebars key/value pairs of options
*/
export default function eachHelper(params, hash, blocks) {
var list = params[0]; | true |
Other | emberjs | ember.js | 6f769aab58d9cad6195859d8ec1b6f66ab134fb3.json | Fix broken JSDoc references | packages/ember-htmlbars/lib/helpers/log.js | @@ -13,7 +13,7 @@ import Logger from "ember-metal/logger";
```
@method log
@for Ember.Handlebars.helpers
- @param {String} property
+ @param {*} values
*/
export default function logHelper(values) {
Logger.log.apply(null, values); | true |
Other | emberjs | ember.js | 6f769aab58d9cad6195859d8ec1b6f66ab134fb3.json | Fix broken JSDoc references | packages/ember-htmlbars/lib/helpers/with.js | @@ -34,7 +34,6 @@ import shouldDisplay from "ember-views/streams/should_display";
@method with
@for Ember.Handlebars.helpers
- @param {Function} context
@param {Hash} options
@return {String} HTML string
*/ | true |
Other | emberjs | ember.js | 6f769aab58d9cad6195859d8ec1b6f66ab134fb3.json | Fix broken JSDoc references | packages/ember-htmlbars/lib/keywords.js | @@ -22,7 +22,7 @@ var keywords = o_create(hooks.keywords);
@method _registerHelper
@for Ember.HTMLBars
@param {String} name
- @param {Object|Function} helperFunc the helper function to add
+ @param {Object|Function} keyword the keyword to add
*/
export function registerKeyword(name, keyword) {
keywords[name] = keyword; | true |
Other | emberjs | ember.js | 6f769aab58d9cad6195859d8ec1b6f66ab134fb3.json | Fix broken JSDoc references | packages/ember-htmlbars/lib/keywords/debugger.js | @@ -36,7 +36,6 @@ import Logger from "ember-metal/logger";
```
@method debugger
@for Ember.Handlebars.helpers
- @param {String} property
*/
export default function debuggerKeyword(morph, env, scope) {
/* jshint unused: false, debug: true */ | true |
Other | emberjs | ember.js | 6f769aab58d9cad6195859d8ec1b6f66ab134fb3.json | Fix broken JSDoc references | packages/ember-htmlbars/lib/system/lookup-helper.js | @@ -23,7 +23,6 @@ export var ISNT_HELPER_CACHE = new Cache(1000, function(key) {
@private
@method resolveHelper
- @param {Container} container
@param {String} name the name of the helper to lookup
@return {Handlebars Helper}
*/ | true |
Other | emberjs | ember.js | 6f769aab58d9cad6195859d8ec1b6f66ab134fb3.json | Fix broken JSDoc references | packages/ember-htmlbars/lib/system/make_bound_helper.js | @@ -46,7 +46,7 @@ import { readHash, readArray } from "ember-metal/streams/utils";
@private
@method makeBoundHelper
@for Ember.HTMLBars
- @param {Function} function
+ @param {Function} fn
@since 1.10.0
*/
export default function makeBoundHelper(fn) { | true |
Other | emberjs | ember.js | 6f769aab58d9cad6195859d8ec1b6f66ab134fb3.json | Fix broken JSDoc references | packages/ember-metal/lib/enumerable_utils.js | @@ -76,7 +76,6 @@ var deprecatedFilter = Ember.deprecateFunc('Ember.EnumberableUtils.filter is dep
* @method indexOf
* @deprecated Use ES5's Array.prototype.indexOf instead.
* @param {Object} obj The object to call indexOn on
- * @param {Function} callback The callback to execute
* @param {Object} index The index to start searching from
*
*/ | true |
Other | emberjs | ember.js | 6f769aab58d9cad6195859d8ec1b6f66ab134fb3.json | Fix broken JSDoc references | packages/ember-metal/lib/instrumentation.js | @@ -81,7 +81,7 @@ var time = (function() {
@namespace Ember.Instrumentation
@param {String} [name] Namespaced event name.
- @param {Object} payload
+ @param {Object} _payload
@param {Function} callback Function that you're instrumenting.
@param {Object} binding Context that instrument function is called with.
*/ | true |
Other | emberjs | ember.js | 6f769aab58d9cad6195859d8ec1b6f66ab134fb3.json | Fix broken JSDoc references | packages/ember-metal/lib/observer.js | @@ -29,8 +29,8 @@ function beforeEvent(keyName) {
@method addObserver
@for Ember
@param obj
- @param {String} path
- @param {Object|Function} targetOrMethod
+ @param {String} _path
+ @param {Object|Function} target
@param {Function|String} [method]
*/
export function addObserver(obj, _path, target, method) { | true |
Other | emberjs | ember.js | 6f769aab58d9cad6195859d8ec1b6f66ab134fb3.json | Fix broken JSDoc references | packages/ember-metal/lib/property_set.js | @@ -164,7 +164,7 @@ function setPath(root, path, value, tolerant) {
@method trySet
@for Ember
- @param {Object} obj The object to modify.
+ @param {Object} root The object to modify.
@param {String} path The property path to set
@param {Object} value The value to set
*/ | true |
Other | emberjs | ember.js | 6f769aab58d9cad6195859d8ec1b6f66ab134fb3.json | Fix broken JSDoc references | packages/ember-metal/lib/utils.js | @@ -830,9 +830,9 @@ export function inspect(obj) {
// The following functions are intentionally minified to keep the functions
// below Chrome's function body size inlining limit of 600 chars.
/**
- @param {Object} target
- @param {Function} method
- @param {Array} args
+ @param {Object} t target
+ @param {Function} m method
+ @param {Array} a args
*/
export function apply(t, m, a) {
var l = a && a.length;
@@ -848,9 +848,9 @@ export function apply(t, m, a) {
}
/**
- @param {Object} target
- @param {String} method
- @param {Array} args
+ @param {Object} t target
+ @param {String} m method
+ @param {Array} a args
*/
export function applyStr(t, m, a) {
var l = a && a.length; | true |
Other | emberjs | ember.js | 6f769aab58d9cad6195859d8ec1b6f66ab134fb3.json | Fix broken JSDoc references | packages/ember-metal/lib/watching.js | @@ -33,7 +33,7 @@ import {
@method watch
@for Ember
@param obj
- @param {String} keyName
+ @param {String} _keyPath
*/
function watch(obj, _keyPath, m) {
// can't watch length on Array - it is special... | true |
Other | emberjs | ember.js | 6f769aab58d9cad6195859d8ec1b6f66ab134fb3.json | Fix broken JSDoc references | packages/ember-routing-htmlbars/lib/keywords/action.js | @@ -165,9 +165,6 @@ import closureAction from "ember-routing-htmlbars/keywords/closure-action";
@method action
@for Ember.Handlebars.helpers
- @param {String} actionName
- @param {Object} [context]*
- @param {Hash} options
*/
export default function(morph, env, scope, params, hash, template, inverse, visitor) {
if (Ember.FEATURES.isEnabled("ember-routing-htmlbars-improved-actions")) { | true |
Other | emberjs | ember.js | 6f769aab58d9cad6195859d8ec1b6f66ab134fb3.json | Fix broken JSDoc references | packages/ember-runtime/lib/computed/reduce_computed_macros.js | @@ -681,7 +681,7 @@ function binarySearch(array, item, low, high) {
@method sort
@for Ember.computed
- @param {String} dependentKey
+ @param {String} itemsKey
@param {String or Function} sortDefinition a dependent key to an
array of sort properties (add `:desc` to the arrays sort properties to sort descending) or a function to use when sorting
@return {Ember.ComputedProperty} computes a new sorted array based | true |
Other | emberjs | ember.js | 6f769aab58d9cad6195859d8ec1b6f66ab134fb3.json | Fix broken JSDoc references | packages/ember-runtime/lib/system/tracked_array.js | @@ -292,7 +292,7 @@ TrackedArray.prototype = {
@method ArrayOperation
@private
- @param {String} type The type of the operation. One of
+ @param {String} operation The type of the operation. One of
`Ember.TrackedArray.{RETAIN, INSERT, DELETE}`
@param {Number} count The number of items in this operation.
@param {Array} items The items of the operation, if included. RETAIN and | true |
Other | emberjs | ember.js | 6f769aab58d9cad6195859d8ec1b6f66ab134fb3.json | Fix broken JSDoc references | packages/ember-template-compiler/lib/plugins/transform-angle-bracket-components.js | @@ -6,7 +6,7 @@ function TransformAngleBracketComponents() {
/**
@private
@method transform
- @param {AST} The AST to be transformed.
+ @param {AST} ast The AST to be transformed.
*/
TransformAngleBracketComponents.prototype.transform = function TransformBindAttrToAttributes_transform(ast) {
var walker = new this.syntax.Walker(); | true |
Other | emberjs | ember.js | 6f769aab58d9cad6195859d8ec1b6f66ab134fb3.json | Fix broken JSDoc references | packages/ember-template-compiler/lib/plugins/transform-bind-attr-to-attributes.js | @@ -34,7 +34,7 @@ function TransformBindAttrToAttributes(options) {
/**
@private
@method transform
- @param {AST} The AST to be transformed.
+ @param {AST} ast The AST to be transformed.
*/
TransformBindAttrToAttributes.prototype.transform = function TransformBindAttrToAttributes_transform(ast) {
var plugin = this; | true |
Other | emberjs | ember.js | 6f769aab58d9cad6195859d8ec1b6f66ab134fb3.json | Fix broken JSDoc references | packages/ember-template-compiler/lib/plugins/transform-component-attrs-into-mut.js | @@ -6,7 +6,7 @@ function TransformComponentAttrsIntoMut() {
/**
@private
@method transform
- @param {AST} The AST to be transformed.
+ @param {AST} ast The AST to be transformed.
*/
TransformComponentAttrsIntoMut.prototype.transform = function TransformBindAttrToAttributes_transform(ast) {
var b = this.syntax.builders; | true |
Other | emberjs | ember.js | 6f769aab58d9cad6195859d8ec1b6f66ab134fb3.json | Fix broken JSDoc references | packages/ember-template-compiler/lib/plugins/transform-component-curly-to-readonly.js | @@ -6,7 +6,7 @@ function TransformComponentCurlyToReadonly() {
/**
@private
@method transform
- @param {AST} The AST to be transformed.
+ @param {AST} ast The AST to be transformed.
*/
TransformComponentCurlyToReadonly.prototype.transform = function TransformComponetnCurlyToReadonly_transform(ast) {
var b = this.syntax.builders; | true |
Other | emberjs | ember.js | 6f769aab58d9cad6195859d8ec1b6f66ab134fb3.json | Fix broken JSDoc references | packages/ember-template-compiler/lib/plugins/transform-each-in-to-block-params.js | @@ -33,7 +33,7 @@ function TransformEachInToBlockParams(options) {
/**
@private
@method transform
- @param {AST} The AST to be transformed.
+ @param {AST} ast The AST to be transformed.
*/
TransformEachInToBlockParams.prototype.transform = function TransformEachInToBlockParams_transform(ast) {
var b = this.syntax.builders; | true |
Other | emberjs | ember.js | 6f769aab58d9cad6195859d8ec1b6f66ab134fb3.json | Fix broken JSDoc references | packages/ember-template-compiler/lib/plugins/transform-each-in-to-hash.js | @@ -31,7 +31,7 @@ function TransformEachInToHash(options) {
/**
@private
@method transform
- @param {AST} The AST to be transformed.
+ @param {AST} ast The AST to be transformed.
*/
TransformEachInToHash.prototype.transform = function TransformEachInToHash_transform(ast) {
var pluginContext = this; | true |
Other | emberjs | ember.js | 6f769aab58d9cad6195859d8ec1b6f66ab134fb3.json | Fix broken JSDoc references | packages/ember-template-compiler/lib/plugins/transform-input-on-to-onEvent.js | @@ -33,7 +33,7 @@ function TransformInputOnToOnEvent(options) {
/**
@private
@method transform
- @param {AST} The AST to be transformed.
+ @param {AST} ast The AST to be transformed.
*/
TransformInputOnToOnEvent.prototype.transform = function TransformInputOnToOnEvent_transform(ast) {
const pluginContext = this; | true |
Other | emberjs | ember.js | 6f769aab58d9cad6195859d8ec1b6f66ab134fb3.json | Fix broken JSDoc references | packages/ember-template-compiler/lib/plugins/transform-with-as-to-hash.js | @@ -32,7 +32,7 @@ function TransformWithAsToHash(options) {
/**
@private
@method transform
- @param {AST} The AST to be transformed.
+ @param {AST} ast The AST to be transformed.
*/
TransformWithAsToHash.prototype.transform = function TransformWithAsToHash_transform(ast) {
var pluginContext = this; | true |
Other | emberjs | ember.js | 6f769aab58d9cad6195859d8ec1b6f66ab134fb3.json | Fix broken JSDoc references | packages/ember-views/lib/compat/render_buffer.js | @@ -127,7 +127,6 @@ export function renderComponentWithBuffer(component, contextualElement, dom) {
@method renderBuffer
@namespace Ember
- @param {String} tagName tag name (such as 'div' or 'p') used for the buffer
*/
var RenderBuffer = function(domHelper) { | true |
Other | emberjs | ember.js | 9b70eed5f9a97cb3ba80b9343b263955b6641703.json | Add .watchmanconfig to ignore `tmp`. | .watchmanconfig | @@ -0,0 +1,3 @@
+{
+ "ignore_dirs": ["tmp"]
+} | false |
Other | emberjs | ember.js | b9020834ad51cd414678c8b3101c92907b539f2e.json | Fix a case where AttrMorph was being extended | packages/ember-htmlbars/lib/morphs/attr-morph.js | @@ -12,6 +12,8 @@ export var styleWarning = '' +
function EmberAttrMorph(element, attrName, domHelper, namespace) {
HTMLBarsAttrMorph.call(this, element, attrName, domHelper, namespace);
+
+ this.streamUnsubscribers = null;
}
var proto = EmberAttrMorph.prototype = o_create(HTMLBarsAttrMorph.prototype); | false |
Other | emberjs | ember.js | 25507d3b223e19b6ff0163c8d8ba4ea12465499f.json | Fix bug where parent/ownerView was incorrect
Previously, `parentView` and `ownerView` were set based on `scope`,
which is the “owner tree”. However, it should be based on the
component tree instead.
This commit properly wires up `parentView` and `ownerView`, while
maintaining the correct semantics for the `{{view.foo}}` keyword in
both legacy views and components. | packages/ember-htmlbars/lib/hooks/component.js | @@ -17,8 +17,7 @@ export default function componentHook(renderNode, env, scope, _tagName, params,
isAngleBracket = true;
}
- var read = env.hooks.getValue;
- var parentView = read(scope.view);
+ var parentView = env.view;
var manager = ComponentNodeManager.create(renderNode, env, {
tagName, | true |
Other | emberjs | ember.js | 25507d3b223e19b6ff0163c8d8ba4ea12465499f.json | Fix bug where parent/ownerView was incorrect
Previously, `parentView` and `ownerView` were set based on `scope`,
which is the “owner tree”. However, it should be based on the
component tree instead.
This commit properly wires up `parentView` and `ownerView`, while
maintaining the correct semantics for the `{{view.foo}}` keyword in
both legacy views and components. | packages/ember/tests/component_registration_test.js | @@ -2,6 +2,7 @@ import "ember";
import compile from "ember-template-compiler/system/compile";
import helpers from "ember-htmlbars/helpers";
+import { OutletView } from "ember-routing-views/views/outlet";
var App, registry, container;
var originalHelpers;
@@ -40,7 +41,7 @@ QUnit.module("Application Lifecycle - Component Registration", {
teardown: cleanup
});
-function boot(callback) {
+function boot(callback, startURL="/") {
Ember.run(function() {
App = Ember.Application.create({
name: 'App',
@@ -63,7 +64,7 @@ function boot(callback) {
Ember.run(App, 'advanceReadiness');
Ember.run(function() {
- router.handleURL('/');
+ router.handleURL(startURL);
});
}
@@ -348,3 +349,30 @@ QUnit.test("Components trigger actions in the components context when called fro
Ember.$('#fizzbuzz', "#wrapper").click();
});
+
+QUnit.test("Components receive the top-level view as their ownerView", function(assert) {
+ Ember.TEMPLATES.application = compile("{{outlet}}");
+ Ember.TEMPLATES.index = compile("{{my-component}}");
+ Ember.TEMPLATES['components/my-component'] = compile('<div></div>');
+
+ let component;
+
+ boot(function() {
+ registry.register('component:my-component', Ember.Component.extend({
+ init() {
+ this._super();
+ component = this;
+ }
+ }));
+ });
+
+ // Theses tests are intended to catch a regression where the owner view was
+ // not configured properly. Future refactors may break these tests, which
+ // should not be considered a breaking change to public APIs.
+ let ownerView = component.ownerView;
+ assert.ok(ownerView, "owner view was set");
+ assert.ok(ownerView instanceof OutletView, "owner view has no parent view");
+ assert.notStrictEqual(component, ownerView, "owner view is not itself");
+
+ assert.ok(ownerView._outlets, "owner view has an internal array of outlets");
+}); | true |
Other | emberjs | ember.js | 8ba5e69dfd61ecab92cc6868f91f3dc445aa0fd4.json | Fix canary build publishing.
ember-cli-yuidoc was updated, but the docs script was not updated to the
new command name. This caused the publishing of builds to fail. | package.json | @@ -8,7 +8,7 @@
"pretest": "ember build",
"test": "bin/run-tests.js",
"start": "ember serve",
- "docs": "ember yuidoc"
+ "docs": "ember ember-cli-yuidoc"
},
"devDependencies": {
"aws-sdk": "~2.1.5", | false |
Other | emberjs | ember.js | 23c36f5181ed00611692003f1fd57cfc1475f0bc.json | Fix deprecation test messages to {{#each ...}} | packages/ember-template-compiler/tests/plugins/transform-each-in-to-block-params-test.js | @@ -7,21 +7,21 @@ QUnit.test('cannot use block params and keyword syntax together', function() {
throws(function() {
compile('{{#each thing in controller as |other-thing|}}{{thing}}-{{other-thing}}{{/each}}', true);
- }, /You cannot use keyword \(`{{each foo in bar}}`\) and block params \(`{{each bar as \|foo\|}}`\) at the same time\ ./);
+ }, /You cannot use keyword \(`{{#each foo in bar}}`\) and block params \(`{{#each bar as \|foo\|}}`\) at the same time\ ./);
});
-QUnit.test('using {{each in}} syntax is deprecated for blocks', function() {
+QUnit.test('using {{#each in}} syntax is deprecated for blocks', function() {
expect(1);
expectDeprecation(function() {
compile('\n\n {{#each foo in model}}{{/each}}', { moduleName: 'foo/bar/baz' });
- }, `Using the '{{each item in model}}' form of the {{each}} helper ('foo/bar/baz' @ L3:C3) is deprecated. Please use the block param form instead ('{{each model as |item|}}').`);
+ }, `Using the '{{#each item in model}}' form of the {{#each}} helper ('foo/bar/baz' @ L3:C3) is deprecated. Please use the block param form instead ('{{#each model as |item|}}').`);
});
-QUnit.test('using {{each in}} syntax is deprecated for non-block statemens', function() {
+QUnit.test('using {{#each in}} syntax is deprecated for non-block statemens', function() {
expect(1);
expectDeprecation(function() {
compile('\n\n {{each foo in model}}', { moduleName: 'foo/bar/baz' });
- }, `Using the '{{each item in model}}' form of the {{each}} helper ('foo/bar/baz' @ L3:C3) is deprecated. Please use the block param form instead ('{{each model as |item|}}').`);
+ }, `Using the '{{#each item in model}}' form of the {{#each}} helper ('foo/bar/baz' @ L3:C3) is deprecated. Please use the block param form instead ('{{#each model as |item|}}').`);
}); | false |
Other | emberjs | ember.js | 0738330bc1575b2515bdee1c9721e49b93c57cf5.json | Move query parameter cofiguration into the Route | packages/ember-routing-views/lib/views/link.js | @@ -297,7 +297,13 @@ var LinkComponent = EmberComponent.extend({
return false;
}
- get(this, '_routing').transitionTo(get(this, 'targetRouteName'), get(this, 'models'), get(this, 'queryParams.values'), get(this, 'attrs.replace'));
+ var routing = get(this, '_routing');
+ var targetRouteName = get(this, 'targetRouteName');
+ var models = get(this, 'models');
+ var queryParamValues = get(this, 'queryParams.values');
+ var shouldReplace = get(this, 'attrs.replace');
+
+ routing.transitionTo(targetRouteName, models, queryParamValues, shouldReplace);
},
queryParams: null,
@@ -312,6 +318,7 @@ var LinkComponent = EmberComponent.extend({
@property href
**/
href: computed('models', 'targetRouteName', '_routing.currentState', function computeLinkViewHref() {
+
if (get(this, 'tagName') !== 'a') { return; }
var targetRouteName = get(this, 'targetRouteName');
@@ -320,7 +327,8 @@ var LinkComponent = EmberComponent.extend({
if (get(this, 'loading')) { return get(this, 'loadingHref'); }
var routing = get(this, '_routing');
- return routing.generateURL(targetRouteName, models, get(this, 'queryParams.values'));
+ var queryParams = get(this, 'queryParams.values');
+ return routing.generateURL(targetRouteName, models, queryParams);
}),
loading: computed('models', 'targetRouteName', function() { | true |
Other | emberjs | ember.js | 0738330bc1575b2515bdee1c9721e49b93c57cf5.json | Move query parameter cofiguration into the Route | packages/ember-routing/lib/ext/controller.js | @@ -1,10 +1,5 @@
import Ember from "ember-metal/core"; // FEATURES, deprecate
import { get } from "ember-metal/property_get";
-import { set } from "ember-metal/property_set";
-import { computed } from "ember-metal/computed";
-import { meta } from "ember-metal/utils";
-import merge from "ember-metal/merge";
-
import ControllerMixin from "ember-runtime/mixins/controller";
/**
@@ -15,11 +10,6 @@ import ControllerMixin from "ember-runtime/mixins/controller";
ControllerMixin.reopen({
concatenatedProperties: ['queryParams'],
- init() {
- this._super(...arguments);
- listenForQueryParamChanges(this);
- },
-
/**
Defines which query parameters the controller accepts.
If you give the names ['category','page'] it will bind
@@ -35,125 +25,18 @@ ControllerMixin.reopen({
@property _qpDelegate
@private
*/
- _qpDelegate: null,
-
- /**
- @property _normalizedQueryParams
- @private
- */
- _normalizedQueryParams: computed(function() {
- var m = meta(this);
- if (m.proto !== this) {
- return get(m.proto, '_normalizedQueryParams');
- }
-
- var queryParams = get(this, 'queryParams');
- if (queryParams._qpMap) {
- return queryParams._qpMap;
- }
-
- var qpMap = queryParams._qpMap = {};
-
- for (var i = 0, len = queryParams.length; i < len; ++i) {
- accumulateQueryParamDescriptors(queryParams[i], qpMap);
- }
-
- return qpMap;
- }),
-
- /**
- @property _cacheMeta
- @private
- */
- _cacheMeta: computed(function() {
- var m = meta(this);
- if (m.proto !== this) {
- return get(m.proto, '_cacheMeta');
- }
-
- var cacheMeta = {};
- var qpMap = get(this, '_normalizedQueryParams');
- for (var prop in qpMap) {
- if (!qpMap.hasOwnProperty(prop)) { continue; }
-
- var qp = qpMap[prop];
- var scope = qp.scope;
- var parts;
-
- if (scope === 'controller') {
- parts = [];
- }
-
- cacheMeta[prop] = {
- parts: parts, // provided by route if 'model' scope
- values: null, // provided by route
- scope: scope,
- prefix: "",
- def: get(this, prop)
- };
- }
-
- return cacheMeta;
- }),
-
- /**
- @method _updateCacheParams
- @private
- */
- _updateCacheParams(params) {
- var cacheMeta = get(this, '_cacheMeta');
- for (var prop in cacheMeta) {
- if (!cacheMeta.hasOwnProperty(prop)) { continue; }
- var propMeta = cacheMeta[prop];
- propMeta.values = params;
-
- var cacheKey = this._calculateCacheKey(propMeta.prefix, propMeta.parts, propMeta.values);
- var cache = this._bucketCache;
-
- if (cache) {
- var value = cache.lookup(cacheKey, prop, propMeta.def);
- set(this, prop, value);
- }
- }
- },
+ _qpDelegate: null, // set by route
/**
@method _qpChanged
@private
*/
_qpChanged(controller, _prop) {
var prop = _prop.substr(0, _prop.length-3);
- var cacheMeta = get(controller, '_cacheMeta');
- var propCache = cacheMeta[prop];
- var cacheKey = controller._calculateCacheKey(propCache.prefix || "", propCache.parts, propCache.values);
- var value = get(controller, prop);
-
- // 1. Update model-dep cache
- var cache = this._bucketCache;
- if (cache) {
- controller._bucketCache.stash(cacheKey, prop, value);
- }
- // 2. Notify a delegate (e.g. to fire a qp transition)
var delegate = controller._qpDelegate;
- if (delegate) {
- delegate(controller, prop);
- }
- },
-
- /**
- @method _calculateCacheKey
- @private
- */
- _calculateCacheKey(prefix, _parts, values) {
- var parts = _parts || [];
- var suffixes = "";
- for (var i = 0, len = parts.length; i < len; ++i) {
- var part = parts[i];
- var value = get(values, part);
- suffixes += "::" + part + ":" + value;
- }
- return prefix + suffixes.replace(ALL_PERIODS_REGEX, '-');
+ var value = get(controller, prop);
+ delegate(prop, value);
},
/**
@@ -317,39 +200,4 @@ ControllerMixin.reopen({
}
});
-var ALL_PERIODS_REGEX = /\./g;
-
-function accumulateQueryParamDescriptors(_desc, accum) {
- var desc = _desc;
- var 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;
- }
-}
-
-function listenForQueryParamChanges(controller) {
- var qpMap = get(controller, '_normalizedQueryParams');
- for (var prop in qpMap) {
- if (!qpMap.hasOwnProperty(prop)) { continue; }
- controller.addObserver(prop + '.[]', controller, controller._qpChanged);
- }
-}
-
-
export default ControllerMixin; | true |
Other | emberjs | ember.js | 0738330bc1575b2515bdee1c9721e49b93c57cf5.json | Move query parameter cofiguration into the Route | packages/ember-routing/lib/services/routing.js | @@ -46,7 +46,8 @@ var RoutingService = Service.extend({
},
normalizeQueryParams(routeName, models, queryParams) {
- get(this, 'router')._prepareQueryParams(routeName, models, queryParams);
+ var router = get(this, 'router');
+ router._prepareQueryParams(routeName, models, queryParams);
},
generateURL(routeName, models, queryParams) { | true |
Other | emberjs | ember.js | 0738330bc1575b2515bdee1c9721e49b93c57cf5.json | Move query parameter cofiguration into the Route | packages/ember-routing/lib/system/generate_controller.js | @@ -65,6 +65,7 @@ export function generateControllerFactory(container, controllerName, context) {
*/
export default function generateController(container, controllerName, context) {
generateControllerFactory(container, controllerName, context);
+
var fullName = `controller:${controllerName}`;
var instance = container.lookup(fullName);
| true |
Other | emberjs | ember.js | 0738330bc1575b2515bdee1c9721e49b93c57cf5.json | Move query parameter cofiguration into the Route | packages/ember-routing/lib/system/route.js | @@ -21,7 +21,14 @@ import EmberObject from "ember-runtime/system/object";
import Evented from "ember-runtime/mixins/evented";
import ActionHandler from "ember-runtime/mixins/action_handler";
import generateController from "ember-routing/system/generate_controller";
-import { stashParamNames } from "ember-routing/utils";
+import {
+ generateControllerFactory
+} from "ember-routing/system/generate_controller";
+import {
+ stashParamNames,
+ normalizeControllerQueryParams,
+ calculateCacheKey
+} from "ember-routing/utils";
var slice = Array.prototype.slice;
@@ -92,61 +99,134 @@ var Route = EmberObject.extend(ActionHandler, Evented, {
@property _qp
*/
_qp: computed(function() {
- var controllerName = this.controllerName || this.routeName;
- var controllerClass = this.container.lookupFactory(`controller:${controllerName}`);
+ var controllerProto, combinedQueryParameterConfiguration;
- if (!controllerClass) {
- return defaultQPMeta;
+ var controllerName = this.controllerName || this.routeName;
+ var definedControllerClass = this.container.lookupFactory(`controller:${controllerName}`);
+ var queryParameterConfiguraton = get(this, 'queryParams');
+ var hasRouterDefinedQueryParams = !!keys(queryParameterConfiguraton).length;
+
+ if (definedControllerClass) {
+ // the developer has authored a controller class in their application for this route
+ // access the prototype, find its query params and normalize their object shape
+ // them merge in the query params for the route. As a mergedProperty, Route#queryParams is always
+ // at least `{}`
+ controllerProto = definedControllerClass.proto();
+
+ var controllerDefinedQueryParameterConfiguration = get(controllerProto, 'queryParams');
+ var normalizedControllerQueryParameterConfiguration = normalizeControllerQueryParams(controllerDefinedQueryParameterConfiguration);
+
+ combinedQueryParameterConfiguration = mergeEachQueryParams(normalizedControllerQueryParameterConfiguration, queryParameterConfiguraton);
+
+ } else if (hasRouterDefinedQueryParams) {
+ // the developer has not defined a controller but has supplied route query params.
+ // Generate a class for them so we can later insert default values
+ var generatedControllerClass = generateControllerFactory(this.container, controllerName);
+ controllerProto = generatedControllerClass.proto();
+ combinedQueryParameterConfiguration = queryParameterConfiguraton;
}
- var controllerProto = controllerClass.proto();
- var qpProps = get(controllerProto, '_normalizedQueryParams');
- var cacheMeta = get(controllerProto, '_cacheMeta');
-
var qps = [];
var map = {};
- for (var propName in qpProps) {
- if (!qpProps.hasOwnProperty(propName)) { continue; }
+ var propertyNames = [];
+
+ for (var propName in combinedQueryParameterConfiguration) {
+ if (!combinedQueryParameterConfiguration.hasOwnProperty(propName)) { continue; }
+
+ // to support the dubious feature of using unknownProperty
+ // on queryParams configuration
+ if (propName === 'unknownProperty' || propName === '_super') {
+ // possible todo: issue deprecation warning?
+ continue;
+ }
+
+ var desc = combinedQueryParameterConfiguration[propName];
+
+ // apply default values to controllers
+ // detect that default value defined on router config
+ if (desc.hasOwnProperty('defaultValue')) {
+ // detect that property was not defined on controller
+ if (controllerProto[propName] === undefined) {
+ controllerProto[propName] = desc.defaultValue;
+ }
+ // else { TODO
+ // // the default value was set both on route and controller. Throw error;
+ // }
+ }
+
+ var scope = desc.scope || 'model';
+ var parts;
+
+ if (scope === 'controller') {
+ parts = [];
+ }
- var desc = qpProps[propName];
var urlKey = desc.as || this.serializeQueryParamKey(propName);
var defaultValue = get(controllerProto, propName);
if (isArray(defaultValue)) {
defaultValue = Ember.A(defaultValue.slice());
}
- var type = typeOf(defaultValue);
+ var type = desc.type || typeOf(defaultValue);
+
var defaultValueSerialized = this.serializeQueryParam(defaultValue, urlKey, type);
- var fprop = `${controllerName}:${propName}`;
+ var scopedPropertyName = `${controllerName}:${propName}`;
var qp = {
- def: defaultValue,
- sdef: defaultValueSerialized,
+ undecoratedDefaultValue: get(controllerProto, propName),
+ defaultValue: defaultValue,
+ serializedDefaultValue: defaultValueSerialized,
+ serializedValue: defaultValueSerialized,
+
type: type,
urlKey: urlKey,
prop: propName,
- fprop: fprop,
+ scopedPropertyName: scopedPropertyName,
ctrl: controllerName,
- cProto: controllerProto,
- svalue: defaultValueSerialized,
- cacheType: desc.scope,
route: this,
- cacheMeta: cacheMeta[propName]
+ parts: parts, // provided later when stashNames is called if 'model' scope
+ values: null, // provided later when setup is called. no idea why.
+ scope: scope,
+ prefix: ""
};
- map[propName] = map[urlKey] = map[fprop] = qp;
+ map[propName] = map[urlKey] = map[scopedPropertyName] = qp;
qps.push(qp);
+ propertyNames.push(propName);
}
return {
qps: qps,
map: map,
+ propertyNames: propertyNames,
states: {
- active: (controller, prop) => {
- return this._activeQPChanged(controller, map[prop]);
+ /*
+ Called when a query parameter changes in the URL, this route cares
+ about that query parameter, but the route is not currently
+ in the active route hierarchy.
+ */
+ inactive: (prop, value) => {
+ var qp = map[prop];
+ this._qpChanged(prop, value, qp);
+ },
+ /*
+ Called when a query parameter changes in the URL, this route cares
+ about that query parameter, and the route is currently
+ in the active route hierarchy.
+ */
+ active: (prop, value) => {
+ var qp = map[prop];
+ this._qpChanged(prop, value, qp);
+ return this._activeQPChanged(map[prop], value);
},
- allowOverrides: (controller, prop) => {
- return this._updatingQPChanged(controller, map[prop]);
+ /*
+ Called when a value of a query parameter this route handles changes in a controller
+ and the route is currently in the active route hierarchy.
+ */
+ allowOverrides: (prop, value) => {
+ var qp = map[prop];
+ this._qpChanged(prop, value, qp);
+ return this._updatingQPChanged(map[prop]);
}
}
};
@@ -184,45 +264,30 @@ var Route = EmberObject.extend(ActionHandler, Evented, {
for (var i = 0; i < len; ++i) {
var qp = qps[i];
- var cacheMeta = qp.cacheMeta;
- if (cacheMeta.scope === 'model') {
- cacheMeta.parts = namePaths;
+ if (qp.scope === 'model') {
+ qp.parts = namePaths;
}
- cacheMeta.prefix = qp.ctrl;
+ qp.prefix = qp.ctrl;
}
},
- /**
- @private
-
- @property _updateSerializedQPValue
- */
- _updateSerializedQPValue(controller, qp) {
- var value = get(controller, qp.prop);
- qp.svalue = this.serializeQueryParam(value, qp.urlKey, qp.type);
- },
-
/**
@private
@property _activeQPChanged
*/
- _activeQPChanged(controller, qp) {
- var value = get(controller, qp.prop);
- this.router._queuedQPChanges[qp.fprop] = value;
- run.once(this, this._fireQueryParamTransition);
+ _activeQPChanged(qp, value) {
+ var router = this.router;
+ router._activeQPChanged(qp.scopedPropertyName, value);
},
/**
@private
@method _updatingQPChanged
*/
- _updatingQPChanged(controller, qp) {
+ _updatingQPChanged(qp) {
var router = this.router;
- if (!router._qpUpdates) {
- router._qpUpdates = {};
- }
- router._qpUpdates[qp.urlKey] = true;
+ router._updatingQPChanged(qp.urlKey);
},
mergedProperties: ['events', 'queryParams'],
@@ -305,16 +370,6 @@ var Route = EmberObject.extend(ActionHandler, Evented, {
return value;
},
-
- /**
- @private
- @property _fireQueryParamTransition
- */
- _fireQueryParamTransition() {
- this.transitionTo({ queryParams: this.router._queuedQPChanges });
- this.router._queuedQPChanges = {};
- },
-
/**
@private
@@ -367,8 +422,7 @@ var Route = EmberObject.extend(ActionHandler, Evented, {
*/
_reset(isExiting, transition) {
var controller = this.controller;
-
- controller._qpDelegate = null;
+ controller._qpDelegate = get(this, '_qp.states.inactive');
this.resetController(controller, isExiting, transition);
},
@@ -707,14 +761,15 @@ var Route = EmberObject.extend(ActionHandler, Evented, {
value = route.deserializeQueryParam(svalue, qp.urlKey, qp.type);
} else {
// No QP provided; use default value.
- svalue = qp.sdef;
- value = copyDefaultValue(qp.def);
+ svalue = qp.serializedDefaultValue;
+ value = copyDefaultValue(qp.defaultValue);
}
}
- controller._qpDelegate = null;
- var thisQueryParamChanged = (svalue !== qp.svalue);
+ controller._qpDelegate = get(this, '_qp.states.inactive');
+
+ var thisQueryParamChanged = (svalue !== qp.serializedValue);
if (thisQueryParamChanged) {
if (transition.queryParamsOnly && replaceUrl !== false) {
var options = route._optionsForQueryParam(qp);
@@ -731,9 +786,9 @@ var Route = EmberObject.extend(ActionHandler, Evented, {
}
// Stash current serialized value of controller.
- qp.svalue = svalue;
+ qp.serializedValue = svalue;
- var thisQueryParamHasDefaultValue = (qp.sdef === svalue);
+ var thisQueryParamHasDefaultValue = (qp.serializedDefaultValue === svalue);
if (!thisQueryParamHasDefaultValue) {
finalParams.push({
value: svalue,
@@ -1074,27 +1129,54 @@ var Route = EmberObject.extend(ActionHandler, Evented, {
@method setup
*/
setup(context, transition) {
+ var controller;
+
var controllerName = this.controllerName || this.routeName;
- var controller = this.controllerFor(controllerName, true);
+ var definedController = this.controllerFor(controllerName, true);
- if (!controller) {
+ if (!definedController) {
controller = this.generateController(controllerName, context);
+ } else {
+ controller = definedController;
}
// Assign the route's controller so that it can more easily be
- // referenced in action handlers
- this.controller = controller;
+ // referenced in action handlers. Side effects. Side effects everywhere.
+ if (!this.controller) {
+ var propNames = get(this, '_qp.propertyNames');
+ addQueryParamsObservers(controller, propNames);
+ this.controller = controller;
+ }
if (this.setupControllers) {
Ember.deprecate("Ember.Route.setupControllers is deprecated. Please use Ember.Route.setupController(controller, model) instead.");
this.setupControllers(controller, context);
} else {
- var states = get(this, '_qp.states');
+ var queryParams = get(this, '_qp');
+
+ var states = queryParams.states;
if (transition) {
// Update the model dep values used to calculate cache keys.
stashParamNames(this.router, transition.state.handlerInfos);
- controller._updateCacheParams(transition.params);
+
+ var params = transition.params;
+ var allParams = queryParams.propertyNames;
+ var cache = this._bucketCache;
+
+ forEach(allParams, function(prop) {
+ var aQp = queryParams.map[prop];
+
+ aQp.values = params;
+ var cacheKey = calculateCacheKey(aQp.prefix, aQp.parts, aQp.values);
+
+ if (cache) {
+ var value = cache.lookup(cacheKey, prop, aQp.undecoratedDefaultValue);
+ set(controller, prop, value);
+ }
+ });
+
}
+
controller._qpDelegate = states.allowOverrides;
if (transition) {
@@ -1113,6 +1195,23 @@ var Route = EmberObject.extend(ActionHandler, Evented, {
}
},
+ /*
+ Called when a query parameter for this route changes, regardless of whether the route
+ is currently part of the active route hierarchy. This will update the query parameter's
+ value in the cache so if this route becomes active, the cache value has been updated.
+ */
+ _qpChanged(prop, value, qp) {
+ if (!qp) { return; }
+
+ var cacheKey = calculateCacheKey(qp.prefix || "", qp.parts, qp.values);
+
+ // Update model-dep cache
+ var cache = this._bucketCache;
+ if (cache) {
+ cache.stash(cacheKey, prop, value);
+ }
+
+ },
/**
This hook is the first of the route entry validation hooks
called when an attempt is made to transition into a route
@@ -1326,7 +1425,6 @@ var Route = EmberObject.extend(ActionHandler, Evented, {
*/
model(params, transition) {
var match, name, sawParams, value;
-
var queryParams = get(this, '_qp.map');
for (var prop in params) {
@@ -1443,7 +1541,7 @@ var Route = EmberObject.extend(ActionHandler, Evented, {
in order to populate the URL.
@method serialize
- @param {Object} model the route's model
+ @param {Object} model the routes model
@param {Array} params an Array of parameter names for the current
route (in the example, `['post_id']`.
@return {Object} the serialized parameters
@@ -1931,12 +2029,6 @@ var Route = EmberObject.extend(ActionHandler, Evented, {
}
});
-var defaultQPMeta = {
- qps: [],
- map: {},
- states: {}
-};
-
function parentRoute(route) {
var handlerInfo = handlerInfoFor(route, route.router.router.state.handlerInfos, -1);
return handlerInfo && handlerInfo.handler;
@@ -2050,7 +2142,7 @@ function getQueryParamsFor(route, state) {
var qpValueWasPassedIn = (qp.prop in fullQueryParams);
params[qp.prop] = qpValueWasPassedIn ?
fullQueryParams[qp.prop] :
- copyDefaultValue(qp.def);
+ copyDefaultValue(qp.defaultValue);
}
return params;
@@ -2063,4 +2155,50 @@ function copyDefaultValue(value) {
return value;
}
+/*
+ Merges all query parameters from a controller with those from
+ a route, returning a new object and avoiding any mutations to
+ the existing objects.
+*/
+function mergeEachQueryParams(controllerQP, routeQP) {
+ var keysMerged = {};
+
+ // needs to be an Ember.Object to support
+ // getting a query params property unknownProperty.
+ // It'd be great to deprecate this for 2.0
+ var qps = {};
+
+ // first loop over all controller qps, merging them any matching route qps
+ // into a new empty object to avoid mutating.
+ for (var cqpName in controllerQP) {
+ if (!controllerQP.hasOwnProperty(cqpName)) { continue; }
+
+ var newControllerParameterConfiguration = {};
+ merge(newControllerParameterConfiguration, controllerQP[cqpName], routeQP[cqpName]);
+
+ qps[cqpName] = newControllerParameterConfiguration;
+
+ // allows us to skip this QP when we check route QPs.
+ keysMerged[cqpName] = true;
+ }
+
+ // loop over all route qps, skipping those that were merged in the first pass
+ // because they also appear in controller qps
+ for (var rqpName in routeQP) {
+ if (!routeQP.hasOwnProperty(rqpName) || keysMerged[rqpName]) { continue; }
+
+ var newRouteParameterConfiguration = {};
+ merge(newRouteParameterConfiguration, routeQP[rqpName], controllerQP[rqpName]);
+ qps[rqpName] = newRouteParameterConfiguration;
+ }
+
+ return qps;
+}
+
+function addQueryParamsObservers(controller, propNames) {
+ forEach(propNames, function(prop) {
+ controller.addObserver(prop + '.[]', controller, controller._qpChanged);
+ });
+}
+
export default Route; | true |
Other | emberjs | ember.js | 0738330bc1575b2515bdee1c9721e49b93c57cf5.json | Move query parameter cofiguration into the Route | packages/ember-routing/lib/system/router.js | @@ -6,7 +6,6 @@ import { defineProperty } from "ember-metal/properties";
import { computed } from "ember-metal/computed";
import merge from "ember-metal/merge";
import run from "ember-metal/run_loop";
-
import { fmt } from "ember-runtime/system/string";
import EmberObject from "ember-runtime/system/object";
import Evented from "ember-runtime/mixins/evented";
@@ -15,10 +14,10 @@ import EmberLocation from "ember-routing/location/api";
import {
routeArgs,
getActiveTargetName,
- stashParamNames
+ stashParamNames,
+ calculateCacheKey
} from "ember-routing/utils";
import create from 'ember-metal/platform/create';
-
import RouterState from "./router_state";
/**
@@ -101,6 +100,15 @@ var EmberRouter = EmberObject.extend(Evented, {
init() {
this._activeViews = {};
this._qpCache = {};
+ this._resetQueuedQueryParameterChanges();
+ },
+
+ /*
+ Resets all pending query paramter changes.
+ Called after transitioning to a new route
+ based on query parameter changes.
+ */
+ _resetQueuedQueryParameterChanges() {
this._queuedQPChanges = {};
},
@@ -361,6 +369,45 @@ var EmberRouter = EmberObject.extend(Evented, {
return this._activeViews[templateName];
},
+ /*
+ Called when an active route's query parameter has changed.
+ These changes are batched into a runloop run and trigger
+ a single transition.
+ */
+ _activeQPChanged(queryParameterName, newValue) {
+ this._queuedQPChanges[queryParameterName] = newValue;
+ run.once(this, this._fireQueryParamTransition);
+ },
+
+ _updatingQPChanged(queryParameterName) {
+ if (!this._qpUpdates) {
+ this._qpUpdates = {};
+ }
+ this._qpUpdates[queryParameterName] = true;
+ },
+
+ /*
+ Triggers a transition to a route based on query parameter changes.
+ This is called once per runloop, to batch changes.
+
+ e.g.
+
+ if these methods are called in succession:
+ this._activeQPChanged('foo', '10');
+ // results in _queuedQPChanges = {foo: '10'}
+ this._activeQPChanged('bar', false);
+ // results in _queuedQPChanges = {foo: '10', bar: false}
+
+
+ _queuedQPChanges will represent both of these changes
+ and the transition using `transitionTo` will be triggered
+ once.
+ */
+ _fireQueryParamTransition() {
+ this.transitionTo({ queryParams: this._queuedQPChanges });
+ this._resetQueuedQueryParameterChanges();
+ },
+
_connectActiveComponentNode(templateName, componentNode) {
Ember.assert('cannot connect an activeView that already exists', !this._activeViews[templateName]);
@@ -500,7 +547,7 @@ var EmberRouter = EmberObject.extend(Evented, {
"`%@` and `%@` map to `%@`. You can fix this by mapping " +
"one of the controller properties to a different query " +
"param key via the `as` config option, e.g. `%@: { as: 'other-%@' }`",
- [qps[0].qp.fprop, qps[1] ? qps[1].qp.fprop : "", qps[0].qp.urlKey, qps[0].qp.prop, qps[0].qp.prop]), qps.length <= 1);
+ [qps[0].qp.scopedPropertyName, qps[1] ? qps[1].qp.scopedPropertyName : "", qps[0].qp.urlKey, qps[0].qp.prop, qps[0].qp.prop]), qps.length <= 1);
var qp = qps[0].qp;
queryParams[qp.urlKey] = qp.route.serializeQueryParam(qps[0].value, qp.urlKey, qp.type);
}
@@ -517,7 +564,7 @@ var EmberRouter = EmberObject.extend(Evented, {
var qps = this._queryParamsFor(targetRouteName);
for (var key in queryParams) {
var qp = qps.map[key];
- if (qp && qp.sdef === queryParams[key]) {
+ if (qp && qp.serializedDefaultValue === queryParams[key]) {
delete queryParams[key];
}
}
@@ -581,30 +628,10 @@ var EmberRouter = EmberObject.extend(Evented, {
};
},
- /*
- becomeResolved: function(payload, resolvedContext) {
- var params = this.serialize(resolvedContext);
-
- if (payload) {
- this.stashResolvedModel(payload, resolvedContext);
- payload.params = payload.params || {};
- payload.params[this.name] = params;
- }
-
- return this.factory('resolved', {
- context: resolvedContext,
- name: this.name,
- handler: this.handler,
- params: params
- });
- },
- */
-
_hydrateUnsuppliedQueryParams(leafRouteName, contexts, queryParams) {
var state = calculatePostTransitionState(this, leafRouteName, contexts);
var handlerInfos = state.handlerInfos;
var appCache = this._bucketCache;
-
stashParamNames(this, handlerInfos);
for (var i = 0, len = handlerInfos.length; i < len; ++i) {
@@ -613,20 +640,18 @@ var EmberRouter = EmberObject.extend(Evented, {
for (var j = 0, qpLen = qpMeta.qps.length; j < qpLen; ++j) {
var qp = qpMeta.qps[j];
+
var presentProp = qp.prop in queryParams && qp.prop ||
- qp.fprop in queryParams && qp.fprop;
+ qp.scopedPropertyName in queryParams && qp.scopedPropertyName;
if (presentProp) {
- if (presentProp !== qp.fprop) {
- queryParams[qp.fprop] = queryParams[presentProp];
+ if (presentProp !== qp.scopedPropertyName) {
+ queryParams[qp.scopedPropertyName] = queryParams[presentProp];
delete queryParams[presentProp];
}
} else {
- var controllerProto = qp.cProto;
- var cacheMeta = get(controllerProto, '_cacheMeta');
-
- var cacheKey = controllerProto._calculateCacheKey(qp.ctrl, cacheMeta[qp.prop].parts, state.params);
- queryParams[qp.fprop] = appCache.lookup(cacheKey, qp.prop, qp.def);
+ var cacheKey = calculateCacheKey(qp.ctrl, qp.parts, state.params);
+ queryParams[qp.scopedPropertyName] = appCache.lookup(cacheKey, qp.prop, qp.defaultValue);
}
}
} | true |
Other | emberjs | ember.js | 0738330bc1575b2515bdee1c9721e49b93c57cf5.json | Move query parameter cofiguration into the Route | packages/ember-routing/lib/utils.js | @@ -1,3 +1,6 @@
+import merge from "ember-metal/merge";
+import { get } from "ember-metal/property_get";
+
export function routeArgs(targetRouteName, models, queryParams) {
var args = [];
if (typeof targetRouteName === 'string') {
@@ -42,3 +45,89 @@ export function stashParamNames(router, handlerInfos) {
handlerInfos._namesStashed = true;
}
+
+/*
+ Stolen from Controller
+*/
+export function calculateCacheKey(prefix, _parts, values) {
+ var parts = _parts || [];
+ var suffixes = "";
+ for (var i = 0, len = parts.length; i < len; ++i) {
+ var part = parts[i];
+ var value = get(values, part);
+ suffixes += "::" + part + ":" + value;
+ }
+ return prefix + suffixes.replace(ALL_PERIODS_REGEX, '-');
+}
+var ALL_PERIODS_REGEX = /\./g;
+
+
+/*
+ Controller-defined query parameters can come in three shapes:
+
+ Array
+ queryParams: ['foo', 'bar']
+ Array of simple objects where value is an alias
+ queryParams: [
+ {
+ 'foo': 'rename_foo_to_this'
+ },
+ {
+ 'bar': 'call_bar_this_instead'
+ }
+ ]
+ Array of fully defined objects
+ queryParams: [
+ {
+ 'foo': {
+ as: 'rename_foo_to_this'
+ },
+ }
+ {
+ 'bar': {
+ as: 'call_bar_this_instead',
+ scope: 'controller'
+ }
+ }
+ ]
+
+ This helper normalizes all three possible styles into the
+ 'Array of fully defined objects' style.
+*/
+export function normalizeControllerQueryParams(queryParams) {
+ if (queryParams._qpMap) {
+ return queryParams._qpMap;
+ }
+
+ var qpMap = queryParams._qpMap = {};
+
+ for (var i = 0, len = queryParams.length; i < len; ++i) {
+ accumulateQueryParamDescriptors(queryParams[i], qpMap);
+ }
+
+ return qpMap;
+}
+
+function accumulateQueryParamDescriptors(_desc, accum) {
+ var desc = _desc;
+ var 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;
+ }
+} | true |
Other | emberjs | ember.js | 0738330bc1575b2515bdee1c9721e49b93c57cf5.json | Move query parameter cofiguration into the Route | packages/ember-routing/tests/utils_test.js | @@ -0,0 +1,45 @@
+import {
+ normalizeControllerQueryParams
+} from "ember-routing/utils";
+
+
+QUnit.module("Routing query parameter utils - normalizeControllerQueryParams");
+
+QUnit.test("returns the cached value if that has been previously set", function(assert) {
+ var cached = {};
+ var params = ['foo'];
+ params._qpMap = cached;
+
+ var normalized = normalizeControllerQueryParams(params);
+ equal(cached, normalized, "cached value returned if previously set");
+});
+
+QUnit.test("converts array style into verbose object style", function(assert) {
+ var paramName = 'foo';
+ var params = [paramName];
+ var normalized = normalizeControllerQueryParams(params);
+
+ ok(normalized[paramName], "turns the query param name into key");
+ equal(normalized[paramName].as, null, "includes a blank alias in 'as' key");
+ equal(normalized[paramName].scope, "model", "defaults scope to model");
+});
+
+QUnit.test("converts object stlye [{foo: 'an_alias'}]", function(assert) {
+ var paramName = 'foo';
+ var params = [{ 'foo': 'an_alias' }];
+ var normalized = normalizeControllerQueryParams(params);
+
+ ok(normalized[paramName], "retains the query param name as key");
+ equal(normalized[paramName].as, 'an_alias', "includes the provided alias in 'as' key");
+ equal(normalized[paramName].scope, "model", "defaults scope to model");
+});
+
+QUnit.test("retains maximally verbose object stlye [{foo: {as: 'foo'}}]", function(assert) {
+ var paramName = 'foo';
+ var params = [{ 'foo': { as: 'an_alias' } }];
+ var normalized = normalizeControllerQueryParams(params);
+
+ ok(normalized[paramName], "retains the query param name as key");
+ equal(normalized[paramName].as, 'an_alias', "includes the provided alias in 'as' key");
+ equal(normalized[paramName].scope, "model", "defaults scope to model");
+}); | true |
Other | emberjs | ember.js | 0738330bc1575b2515bdee1c9721e49b93c57cf5.json | Move query parameter cofiguration into the Route | packages/ember/tests/helpers/link_to_test.js | @@ -1404,11 +1404,364 @@ QUnit.test("supplied QP properties can be bound (booleans)", function() {
});
QUnit.test("href updates when unsupplied controller QP props change", function() {
+ Ember.TEMPLATES.index = compile("{{#link-to (query-params foo='lol') id='the-link'}}Index{{/link-to}}");
+
+ bootApplication();
var indexController = container.lookup('controller:index');
+
+ equal(Ember.$('#the-link').attr('href'), '/?foo=lol');
+ Ember.run(indexController, 'set', 'bar', 'BORF');
+ equal(Ember.$('#the-link').attr('href'), '/?bar=BORF&foo=lol');
+ Ember.run(indexController, 'set', 'foo', 'YEAH');
+ equal(Ember.$('#the-link').attr('href'), '/?bar=BORF&foo=lol');
+});
+
+QUnit.test("The {{link-to}} applies activeClass when query params are not changed", function() {
+ Ember.TEMPLATES.index = compile(
+ "{{#link-to (query-params foo='cat') id='cat-link'}}Index{{/link-to}} " +
+ "{{#link-to (query-params foo='dog') id='dog-link'}}Index{{/link-to}} " +
+ "{{#link-to 'index' id='change-nothing'}}Index{{/link-to}}"
+ );
+
+ Ember.TEMPLATES.search = compile(
+ "{{#link-to (query-params search='same') id='same-search'}}Index{{/link-to}} " +
+ "{{#link-to (query-params search='change') id='change-search'}}Index{{/link-to}} " +
+ "{{#link-to (query-params search='same' archive=true) id='same-search-add-archive'}}Index{{/link-to}} " +
+ "{{#link-to (query-params archive=true) id='only-add-archive'}}Index{{/link-to}} " +
+ "{{#link-to (query-params search='same' archive=true) id='both-same'}}Index{{/link-to}} " +
+ "{{#link-to (query-params search='different' archive=true) id='change-one'}}Index{{/link-to}} " +
+ "{{#link-to (query-params search='different' archive=false) id='remove-one'}}Index{{/link-to}} " +
+ "{{outlet}}"
+ );
+
+ Ember.TEMPLATES['search/results'] = compile(
+ "{{#link-to (query-params sort='title') id='same-sort-child-only'}}Index{{/link-to}} " +
+ "{{#link-to (query-params search='same') id='same-search-parent-only'}}Index{{/link-to}} " +
+ "{{#link-to (query-params search='change') id='change-search-parent-only'}}Index{{/link-to}} " +
+ "{{#link-to (query-params search='same' sort='title') id='same-search-same-sort-child-and-parent'}}Index{{/link-to}} " +
+ "{{#link-to (query-params search='same' sort='author') id='same-search-different-sort-child-and-parent'}}Index{{/link-to}} " +
+ "{{#link-to (query-params search='change' sort='title') id='change-search-same-sort-child-and-parent'}}Index{{/link-to}} " +
+ "{{#link-to (query-params foo='dog') id='dog-link'}}Index{{/link-to}} "
+ );
+
+ Router.map(function() {
+ this.resource("search", function() {
+ this.route("results");
+ });
+ });
+
+ App.SearchController = Ember.Controller.extend({
+ queryParams: ['search', 'archive'],
+ search: '',
+ archive: false
+ });
+
+ App.SearchResultsController = Ember.Controller.extend({
+ queryParams: ['sort', 'showDetails'],
+ sort: 'title',
+ showDetails: true
+ });
+
+ bootApplication();
+
+ //Basic tests
+ shouldNotBeActive('#cat-link');
+ shouldNotBeActive('#dog-link');
+ Ember.run(router, 'handleURL', '/?foo=cat');
+ shouldBeActive('#cat-link');
+ shouldNotBeActive('#dog-link');
+ Ember.run(router, 'handleURL', '/?foo=dog');
+ shouldBeActive('#dog-link');
+ shouldNotBeActive('#cat-link');
+ shouldBeActive('#change-nothing');
+
+ //Multiple params
+ Ember.run(function() {
+ router.handleURL("/search?search=same");
+ });
+ shouldBeActive('#same-search');
+ shouldNotBeActive('#change-search');
+ shouldNotBeActive('#same-search-add-archive');
+ shouldNotBeActive('#only-add-archive');
+ shouldNotBeActive('#remove-one');
+
+ Ember.run(function() {
+ router.handleURL("/search?search=same&archive=true");
+ });
+ shouldBeActive('#both-same');
+ shouldNotBeActive('#change-one');
+
+ //Nested Controllers
+ Ember.run(function() {
+ // Note: this is kind of a strange case; sort's default value is 'title',
+ // so this URL shouldn't have been generated in the first place, but
+ // we should also be able to gracefully handle these cases.
+ router.handleURL("/search/results?search=same&sort=title&showDetails=true");
+ });
+ //shouldBeActive('#same-sort-child-only');
+ shouldBeActive('#same-search-parent-only');
+ shouldNotBeActive('#change-search-parent-only');
+ shouldBeActive('#same-search-same-sort-child-and-parent');
+ shouldNotBeActive('#same-search-different-sort-child-and-parent');
+ shouldNotBeActive('#change-search-same-sort-child-and-parent');
+});
+
+QUnit.test("The {{link-to}} applies active class when query-param is number", function() {
+ Ember.TEMPLATES.index = compile(
+ "{{#link-to (query-params page=pageNumber) id='page-link'}}Index{{/link-to}} ");
+
+ App.IndexController = Ember.Controller.extend({
+ queryParams: ['page'],
+ page: 1,
+ pageNumber: 5
+ });
+
+ bootApplication();
+
+ shouldNotBeActive('#page-link');
+ Ember.run(router, 'handleURL', '/?page=5');
+ shouldBeActive('#page-link');
+});
+
+QUnit.test("The {{link-to}} applies active class when query-param is array", function() {
+ Ember.TEMPLATES.index = compile(
+ "{{#link-to (query-params pages=pagesArray) id='array-link'}}Index{{/link-to}} " +
+ "{{#link-to (query-params pages=biggerArray) id='bigger-link'}}Index{{/link-to}} " +
+ "{{#link-to (query-params pages=emptyArray) id='empty-link'}}Index{{/link-to}} "
+ );
+
+ App.IndexController = Ember.Controller.extend({
+ queryParams: ['pages'],
+ pages: [],
+ pagesArray: [1,2],
+ biggerArray: [1,2,3],
+ emptyArray: []
+ });
+
+ bootApplication();
+
+ shouldNotBeActive('#array-link');
+ Ember.run(router, 'handleURL', '/?pages=%5B1%2C2%5D');
+ shouldBeActive('#array-link');
+ shouldNotBeActive('#bigger-link');
+ shouldNotBeActive('#empty-link');
+ Ember.run(router, 'handleURL', '/?pages=%5B2%2C1%5D');
+ shouldNotBeActive('#array-link');
+ shouldNotBeActive('#bigger-link');
+ shouldNotBeActive('#empty-link');
+ Ember.run(router, 'handleURL', '/?pages=%5B1%2C2%2C3%5D');
+ shouldBeActive('#bigger-link');
+ shouldNotBeActive('#array-link');
+ shouldNotBeActive('#empty-link');
+});
+
+QUnit.test("The {{link-to}} helper applies active class to parent route", function() {
+ App.Router.map(function() {
+ this.resource('parent', function() {
+ this.route('child');
+ });
+ });
+
+ Ember.TEMPLATES.application = compile(
+ "{{#link-to 'parent' id='parent-link'}}Parent{{/link-to}} " +
+ "{{#link-to 'parent.child' id='parent-child-link'}}Child{{/link-to}} " +
+ "{{#link-to 'parent' (query-params foo=cat) id='parent-link-qp'}}Parent{{/link-to}} " +
+ "{{outlet}}"
+ );
+
+ App.ParentChildController = Ember.Controller.extend({
+ queryParams: ['foo'],
+ foo: 'bar'
+ });
+
+ bootApplication();
+ shouldNotBeActive('#parent-link');
+ shouldNotBeActive('#parent-child-link');
+ shouldNotBeActive('#parent-link-qp');
+ Ember.run(router, 'handleURL', '/parent/child?foo=dog');
+ shouldBeActive('#parent-link');
+ shouldNotBeActive('#parent-link-qp');
+});
+
+QUnit.test("The {{link-to}} helper disregards query-params in activeness computation when current-when specified", function() {
+ App.Router.map(function() {
+ this.route('parent');
+ });
+
+ Ember.TEMPLATES.application = compile(
+ "{{#link-to 'parent' (query-params page=1) current-when='parent' id='app-link'}}Parent{{/link-to}} {{outlet}}");
+ Ember.TEMPLATES.parent = compile(
+ "{{#link-to 'parent' (query-params page=1) current-when='parent' id='parent-link'}}Parent{{/link-to}} {{outlet}}");
+
+ App.ParentController = Ember.Controller.extend({
+ queryParams: ['page'],
+ page: 1
+ });
+
+ bootApplication();
+ equal(Ember.$('#app-link').attr('href'), '/parent');
+ shouldNotBeActive('#app-link');
+
+ Ember.run(router, 'handleURL', '/parent?page=2');
+ equal(Ember.$('#app-link').attr('href'), '/parent');
+ shouldBeActive('#app-link');
+ equal(Ember.$('#parent-link').attr('href'), '/parent');
+ shouldBeActive('#parent-link');
+
+ var parentController = container.lookup('controller:parent');
+ equal(parentController.get('page'), 2);
+ Ember.run(parentController, 'set', 'page', 3);
+ equal(router.get('location.path'), '/parent?page=3');
+ shouldBeActive('#app-link');
+ shouldBeActive('#parent-link');
+
+ Ember.$('#app-link').click();
+ equal(router.get('location.path'), '/parent');
+});
+
+QUnit.module("The {{link-to}} helper: invoking with query params when defined on a route", {
+ setup() {
+ Ember.run(function() {
+ sharedSetup();
+ App.IndexController = Ember.Controller.extend({
+ boundThing: 'OMG'
+ });
+
+ App.IndexRoute = Ember.Route.extend({
+ queryParams: {
+ foo: {
+ defaultValue: '123'
+ },
+ bar: {
+ defaultValue: 'abc'
+ },
+ abool: {
+ defaultValue: true
+ }
+ }
+ });
+
+ App.AboutRoute = Ember.Route.extend({
+ queryParams: {
+ baz: {
+ defaultValue: 'alex'
+ },
+ bat: {
+ defaultValue: 'borf'
+ }
+ }
+ });
+
+ registry.unregister('router:main');
+ registry.register('router:main', Router);
+ });
+ },
+
+ teardown: sharedTeardown
+});
+
+QUnit.test("doesn't update controller QP properties on current route when invoked", function() {
+ Ember.TEMPLATES.index = compile("{{#link-to 'index' id='the-link'}}Index{{/link-to}}");
+ bootApplication();
+
+ Ember.run(Ember.$('#the-link'), 'click');
+ var indexController = container.lookup('controller:index');
+ deepEqual(indexController.getProperties('foo', 'bar'), { foo: '123', bar: 'abc' }, "controller QP properties not");
+});
+
+QUnit.test("doesn't update controller QP properties on current route when invoked (empty query-params obj)", function() {
+ Ember.TEMPLATES.index = compile("{{#link-to 'index' (query-params) id='the-link'}}Index{{/link-to}}");
+ bootApplication();
+
+ Ember.run(Ember.$('#the-link'), 'click');
+ var indexController = container.lookup('controller:index');
+ deepEqual(indexController.getProperties('foo', 'bar'), { foo: '123', bar: 'abc' }, "controller QP properties not");
+});
+
+QUnit.test("link-to with no params throws", function() {
+ Ember.TEMPLATES.index = compile("{{#link-to id='the-link'}}Index{{/link-to}}");
+ expectAssertion(function() {
+ bootApplication();
+ }, /one or more/);
+});
+
+QUnit.test("doesn't update controller QP properties on current route when invoked (empty query-params obj, inferred route)", function() {
+ Ember.TEMPLATES.index = compile("{{#link-to (query-params) id='the-link'}}Index{{/link-to}}");
+ bootApplication();
+
+ Ember.run(Ember.$('#the-link'), 'click');
+ var indexController = container.lookup('controller:index');
+ deepEqual(indexController.getProperties('foo', 'bar'), { foo: '123', bar: 'abc' }, "controller QP properties not");
+});
+
+QUnit.test("updates controller QP properties on current route when invoked", function() {
+ Ember.TEMPLATES.index = compile("{{#link-to 'index' (query-params foo='456') id='the-link'}}Index{{/link-to}}");
+ bootApplication();
+
+ Ember.run(Ember.$('#the-link'), 'click');
+ var indexController = container.lookup('controller:index');
+ deepEqual(indexController.getProperties('foo', 'bar'), { foo: '456', bar: 'abc' }, "controller QP properties updated");
+});
+
+QUnit.test("updates controller QP properties on current route when invoked (inferred route)", function() {
+ Ember.TEMPLATES.index = compile("{{#link-to (query-params foo='456') id='the-link'}}Index{{/link-to}}");
+ bootApplication();
+
+ Ember.run(Ember.$('#the-link'), 'click');
+ var indexController = container.lookup('controller:index');
+ deepEqual(indexController.getProperties('foo', 'bar'), { foo: '456', bar: 'abc' }, "controller QP properties updated");
+});
+
+QUnit.test("updates controller QP properties on other route after transitioning to that route", function() {
+ Router.map(function() {
+ this.route('about');
+ });
+
+ Ember.TEMPLATES.index = compile("{{#link-to 'about' (query-params baz='lol') id='the-link'}}About{{/link-to}}");
+ bootApplication();
+
+ equal(Ember.$('#the-link').attr('href'), '/about?baz=lol');
+ Ember.run(Ember.$('#the-link'), 'click');
+ var aboutController = container.lookup('controller:about');
+ deepEqual(aboutController.getProperties('baz', 'bat'), { baz: 'lol', bat: 'borf' }, "about controller QP properties updated");
+
+ equal(container.lookup('controller:application').get('currentPath'), "about");
+});
+
+QUnit.test("supplied QP properties can be bound", function() {
+ Ember.TEMPLATES.index = compile("{{#link-to (query-params foo=boundThing) id='the-link'}}Index{{/link-to}}");
+ bootApplication();
+
+ var indexController = container.lookup('controller:index');
+
+
+ equal(Ember.$('#the-link').attr('href'), '/?foo=OMG');
+ Ember.run(indexController, 'set', 'boundThing', "ASL");
+ equal(Ember.$('#the-link').attr('href'), '/?foo=ASL');
+});
+
+QUnit.test("supplied QP properties can be bound (booleans)", function() {
+ var indexController = container.lookup('controller:index');
+ Ember.TEMPLATES.index = compile("{{#link-to (query-params abool=boundThing) id='the-link'}}Index{{/link-to}}");
+
+ bootApplication();
+
+ equal(Ember.$('#the-link').attr('href'), '/?abool=OMG');
+ Ember.run(indexController, 'set', 'boundThing', false);
+ equal(Ember.$('#the-link').attr('href'), '/?abool=false');
+
+ Ember.run(Ember.$('#the-link'), 'click');
+
+ deepEqual(indexController.getProperties('foo', 'bar', 'abool'), { foo: '123', bar: 'abc', abool: false });
+});
+
+QUnit.test("href updates when unsupplied controller QP props change", function() {
Ember.TEMPLATES.index = compile("{{#link-to (query-params foo='lol') id='the-link'}}Index{{/link-to}}");
bootApplication();
+ var indexController = container.lookup('controller:index');
+
equal(Ember.$('#the-link').attr('href'), '/?foo=lol');
Ember.run(indexController, 'set', 'bar', 'BORF');
equal(Ember.$('#the-link').attr('href'), '/?bar=BORF&foo=lol');
@@ -1619,6 +1972,7 @@ QUnit.test("The {{link-to}} helper disregards query-params in activeness computa
equal(router.get('location.path'), '/parent');
});
+
function basicEagerURLUpdateTest(setTagName) {
expect(6);
| true |
Other | emberjs | ember.js | 0738330bc1575b2515bdee1c9721e49b93c57cf5.json | Move query parameter cofiguration into the Route | packages/ember/tests/routing/query_params_test.js | @@ -120,6 +120,29 @@ QUnit.module("Routing w/ Query Params", {
}
});
+QUnit.test("a query param can have define a `type` for type casting", function() {
+ Router.map(function() {
+ this.route("home", { path: '/' });
+ });
+
+ App.HomeRoute = Ember.Route.extend({
+ queryParams: {
+ page: {
+ defaultValue: null,
+ type: 'number'
+ }
+ }
+ });
+
+ bootApplication();
+
+ var controller = container.lookup('controller:home');
+
+ Ember.run(router, 'transitionTo', 'home', { queryParams: { page: '4' } });
+ equal(controller.get('page'), 4);
+
+});
+
QUnit.test("Single query params can be set on ObjectController [DEPRECATED]", function() {
expectDeprecation("Ember.ObjectController is deprecated, please use Ember.Controller and use `model.propertyName`.");
@@ -144,7 +167,7 @@ QUnit.test("Single query params can be set on ObjectController [DEPRECATED]", fu
equal(router.get('location.path'), "/?foo=987");
});
-QUnit.test("Single query params can be set", function() {
+QUnit.test("Single query params can be set on the controller [DEPRECATED]", function() {
Router.map(function() {
this.route("home", { path: '/' });
});
@@ -166,7 +189,32 @@ QUnit.test("Single query params can be set", function() {
equal(router.get('location.path'), "/?foo=987");
});
-QUnit.test("Query params can map to different url keys", function() {
+QUnit.test("Single query params can be set on the route", function() {
+ Router.map(function() {
+ this.route("home", { path: '/' });
+ });
+
+ App.HomeRoute = Ember.Route.extend({
+ queryParams: {
+ foo: {
+ defaultValue: "123"
+ }
+ }
+ });
+
+ bootApplication();
+
+ var controller = container.lookup('controller:home');
+
+ setAndFlush(controller, 'foo', '456');
+
+ equal(router.get('location.path'), "/?foo=456");
+
+ setAndFlush(controller, 'foo', '987');
+ equal(router.get('location.path'), "/?foo=987");
+});
+
+QUnit.test("Query params can map to different url keys configured on the controller [DEPRECATED]", function() {
App.IndexController = Ember.Controller.extend({
queryParams: [{ foo: 'other_foo', bar: { as: 'other_bar' } }],
foo: "FOO",
@@ -190,6 +238,31 @@ QUnit.test("Query params can map to different url keys", function() {
Ember.run(router, 'transitionTo', '/?other_bar=NERK&other_foo=NAW');
});
+QUnit.test("Query params can map to different url keys configured on the route", function() {
+ App.IndexRoute = Ember.Route.extend({
+ queryParams: {
+ foo: { as: 'other_foo', defaultValue: "FOO" },
+ bar: { as: 'other_bar', defaultValue: "BAR" }
+ }
+ });
+
+ bootApplication();
+ equal(router.get('location.path'), "");
+
+ var controller = container.lookup('controller:index');
+
+ setAndFlush(controller, 'foo', 'LEX');
+
+ equal(router.get('location.path'), "/?other_foo=LEX");
+ setAndFlush(controller, 'foo', 'WOO');
+ equal(router.get('location.path'), "/?other_foo=WOO");
+
+ Ember.run(router, 'transitionTo', '/?other_foo=NAW');
+ equal(controller.get('foo'), "NAW");
+
+ setAndFlush(controller, 'bar', 'NERK');
+ Ember.run(router, 'transitionTo', '/?other_bar=NERK&other_foo=NAW');
+});
QUnit.test("Routes have overridable serializeQueryParamKey hook", function() {
App.IndexRoute = Ember.Route.extend({
@@ -210,6 +283,25 @@ QUnit.test("Routes have overridable serializeQueryParamKey hook", function() {
equal(router.get('location.path'), "/?fun-times=woot");
});
+QUnit.test("Routes have overridable serializeQueryParamKey hook and it works with route-configured query params", function() {
+ App.IndexRoute = Ember.Route.extend({
+ queryParams: {
+ funTimes: {
+ defaultValue: ""
+ }
+ },
+ serializeQueryParamKey: Ember.String.dasherize
+ });
+
+ bootApplication();
+ equal(router.get('location.path'), "");
+
+ var controller = container.lookup('controller:index');
+ setAndFlush(controller, 'funTimes', 'woot');
+
+ equal(router.get('location.path'), "/?fun-times=woot");
+});
+
QUnit.test("No replaceURL occurs on startup because default values don't show up in URL", function() {
expect(0);
@@ -223,6 +315,22 @@ QUnit.test("No replaceURL occurs on startup because default values don't show up
bootApplication();
});
+QUnit.test("No replaceURL occurs on startup when configured via Route because default values don't show up in URL", function() {
+ expect(0);
+
+ App.IndexRoute = Ember.Route.extend({
+ queryParams: {
+ foo: {
+ defaultValue: "123"
+ }
+ }
+ });
+
+ expectedReplaceURL = "/?foo=123";
+
+ bootApplication();
+});
+
QUnit.test("Can override inherited QP behavior by specifying queryParams as a computed property", function() {
expect(0);
var SharedMixin = Ember.Mixin.create({
@@ -261,6 +369,24 @@ QUnit.test("model hooks receives query params", function() {
equal(router.get('location.path'), "");
});
+QUnit.test("model hooks receives query params when configred on Route", function() {
+ App.IndexRoute = Ember.Route.extend({
+ queryParams: {
+ omg: {
+ defaultValue: "lol"
+ }
+ },
+ model(params) {
+ deepEqual(params, { omg: 'lol' });
+ }
+ });
+
+ bootApplication();
+
+ equal(router.get('location.path'), "");
+});
+
+
QUnit.test("controllers won't be eagerly instantiated by internal query params logic", function() {
expect(10);
Router.map(function() {
@@ -353,6 +479,7 @@ QUnit.test("controllers won't be eagerly instantiated by internal query params l
equal(router.get('location.path'), "/cats?name=domino", 'url is correct');
});
+
QUnit.test("model hooks receives query params (overridden by incoming url value)", function() {
App.IndexController = Ember.Controller.extend({
queryParams: ['omg'],
@@ -371,6 +498,24 @@ QUnit.test("model hooks receives query params (overridden by incoming url value)
equal(router.get('location.path'), "/?omg=yes");
});
+QUnit.test("model hooks receives query params (overridden by incoming url value) when configured on route", function() {
+ App.IndexRoute = Ember.Route.extend({
+ queryParams: {
+ omg: {
+ defaultValue: 'lol'
+ }
+ },
+ model(params) {
+ deepEqual(params, { omg: 'yes' });
+ }
+ });
+
+ startingURL = "/?omg=yes";
+ bootApplication();
+
+ equal(router.get('location.path'), "/?omg=yes");
+});
+
QUnit.test("Route#paramsFor fetches query params", function() {
expect(1);
@@ -393,6 +538,28 @@ QUnit.test("Route#paramsFor fetches query params", function() {
bootApplication();
});
+QUnit.test("Route#paramsFor fetches query params when configured on the route", function() {
+ expect(1);
+
+ Router.map(function() {
+ this.route('index', { path: '/:something' });
+ });
+
+ App.IndexRoute = Ember.Route.extend({
+ queryParams: {
+ foo: {
+ defaultValue: 'fooapp'
+ }
+ },
+ model(params, transition) {
+ deepEqual(this.paramsFor('index'), { something: 'omg', foo: 'fooapp' }, "could retrieve params for index");
+ }
+ });
+
+ startingURL = "/omg";
+ bootApplication();
+});
+
QUnit.test("Route#paramsFor fetches falsy query params", function() {
expect(1);
@@ -411,6 +578,24 @@ QUnit.test("Route#paramsFor fetches falsy query params", function() {
bootApplication();
});
+QUnit.test("Route#paramsFor fetches falsy query params when they're configured on the route", function() {
+ expect(1);
+
+ App.IndexRoute = Ember.Route.extend({
+ queryParams: {
+ foo: {
+ defaultValue: true
+ }
+ },
+ model(params, transition) {
+ equal(params.foo, false);
+ }
+ });
+
+ startingURL = "/?foo=false";
+ bootApplication();
+});
+
QUnit.test("model hook can query prefix-less application params", function() {
App.ApplicationController = Ember.Controller.extend({
queryParams: ['appomg'],
@@ -440,6 +625,35 @@ QUnit.test("model hook can query prefix-less application params", function() {
equal(router.get('location.path'), "");
});
+QUnit.test("model hook can query prefix-less application params when they're configured on the route", function() {
+ App.ApplicationRoute = Ember.Route.extend({
+ queryParams: {
+ appomg: {
+ defaultValue: 'applol'
+ }
+ },
+ model(params) {
+ deepEqual(params, { appomg: 'applol' });
+ }
+ });
+
+ App.IndexRoute = Ember.Route.extend({
+ queryParams: {
+ omg: {
+ defaultValue: 'lol'
+ }
+ },
+ model(params) {
+ deepEqual(params, { omg: 'lol' });
+ deepEqual(this.paramsFor('application'), { appomg: 'applol' });
+ }
+ });
+
+ bootApplication();
+
+ equal(router.get('location.path'), "");
+});
+
QUnit.test("model hook can query prefix-less application params (overridden by incoming url value)", function() {
App.ApplicationController = Ember.Controller.extend({
queryParams: ['appomg'],
@@ -470,6 +684,37 @@ QUnit.test("model hook can query prefix-less application params (overridden by i
equal(router.get('location.path'), "/?appomg=appyes&omg=yes");
});
+QUnit.test("model hook can query prefix-less application params (overridden by incoming url value) when they're configured on the route", function() {
+ App.ApplicationRoute = Ember.Route.extend({
+ queryParams: {
+ appomg: {
+ defaultValue: 'applol'
+ }
+ },
+ model(params) {
+ deepEqual(params, { appomg: 'appyes' });
+ }
+ });
+
+ App.IndexRoute = Ember.Route.extend({
+ queryParams: {
+ omg: {
+ defaultValue: 'lol'
+ }
+ },
+ model(params) {
+ deepEqual(params, { omg: 'yes' });
+ deepEqual(this.paramsFor('application'), { appomg: 'appyes' });
+ }
+ });
+
+ startingURL = "/?appomg=appyes&omg=yes";
+ bootApplication();
+
+ equal(router.get('location.path'), "/?appomg=appyes&omg=yes");
+});
+
+
QUnit.test("can opt into full transition by setting refreshModel in route queryParams", function() {
expect(6);
App.ApplicationController = Ember.Controller.extend({
@@ -519,6 +764,52 @@ QUnit.test("can opt into full transition by setting refreshModel in route queryP
equal(indexModelCount, 2);
});
+QUnit.test("can opt into full transition by setting refreshModel in route queryParams when all configuration is in route", function() {
+ expect(6);
+
+ var appModelCount = 0;
+ App.ApplicationRoute = Ember.Route.extend({
+ queryParams: {
+ 'appomg': {
+ defaultValue: 'applol'
+ }
+ },
+ model(params) {
+ appModelCount++;
+ }
+ });
+
+ var indexModelCount = 0;
+ App.IndexRoute = Ember.Route.extend({
+ queryParams: {
+ omg: {
+ refreshModel: true,
+ defaultValue: 'lol'
+ }
+ },
+ model(params) {
+ indexModelCount++;
+
+ if (indexModelCount === 1) {
+ deepEqual(params, { omg: 'lol' });
+ } else if (indexModelCount === 2) {
+ deepEqual(params, { omg: 'lex' });
+ }
+ }
+ });
+
+ bootApplication();
+
+ equal(appModelCount, 1);
+ equal(indexModelCount, 1);
+
+ var indexController = container.lookup('controller:index');
+ setAndFlush(indexController, 'omg', 'lex');
+
+ equal(appModelCount, 1);
+ equal(indexModelCount, 2);
+});
+
QUnit.test("Use Ember.get to retrieve query params 'refreshModel' configuration", function() {
expect(6);
App.ApplicationController = Ember.Controller.extend({
@@ -568,6 +859,7 @@ QUnit.test("Use Ember.get to retrieve query params 'refreshModel' configuration"
equal(indexModelCount, 2);
});
+
QUnit.test("can use refreshModel even w URL changes that remove QPs from address bar", function() {
expect(4);
@@ -605,7 +897,40 @@ QUnit.test("can use refreshModel even w URL changes that remove QPs from address
equal(indexController.get('omg'), 'lol');
});
-QUnit.test("warn user that routes query params configuration must be an Object, not an Array", function() {
+QUnit.test("can use refreshModel even w URL changes that remove QPs from address bar when QP configured on route", function() {
+ expect(4);
+
+ var indexModelCount = 0;
+ App.IndexRoute = Ember.Route.extend({
+ queryParams: {
+ omg: {
+ defaultValue: 'lol',
+ refreshModel: true
+ }
+ },
+ model(params) {
+ indexModelCount++;
+
+ var data;
+ if (indexModelCount === 1) {
+ data = 'foo';
+ } else if (indexModelCount === 2) {
+ data = 'lol';
+ }
+
+ deepEqual(params, { omg: data }, "index#model receives right data");
+ }
+ });
+
+ startingURL = '/?omg=foo';
+ bootApplication();
+ handleURL('/');
+
+ var indexController = container.lookup('controller:index');
+ equal(indexController.get('omg'), 'lol');
+});
+
+QUnit.test("warn user that routes query params configuration must be an Object, not an Array", function() {
expect(1);
App.ApplicationRoute = Ember.Route.extend({
@@ -643,6 +968,27 @@ QUnit.test("can opt into a replace query by specifying replace:true in the Route
setAndFlush(appController, 'alex', 'wallace');
});
+QUnit.test("can opt into a replace query by specifying replace:true in the Router config hash when all configuration lives on route", function() {
+ expect(2);
+
+ App.ApplicationRoute = Ember.Route.extend({
+ queryParams: {
+ alex: {
+ defaultValue: 'matchneer',
+ replace: true
+ }
+ }
+ });
+
+ bootApplication();
+
+ equal(router.get('location.path'), "");
+
+ var appController = container.lookup('controller:application');
+ expectedReplaceURL = "/?alex=wallace";
+ setAndFlush(appController, 'alex', 'wallace');
+});
+
QUnit.test("Route query params config can be configured using property name instead of URL key", function() {
expect(2);
App.ApplicationController = Ember.Controller.extend({
@@ -668,6 +1014,27 @@ QUnit.test("Route query params config can be configured using property name inst
setAndFlush(appController, 'commitBy', 'igor_seb');
});
+QUnit.test("Route query params config can be configured using property name instead of URL key when configured on the route", function() {
+ expect(2);
+
+ App.ApplicationRoute = Ember.Route.extend({
+ queryParams: {
+ commitBy: {
+ as: 'commit_by',
+ replace: true
+ }
+ }
+ });
+
+ bootApplication();
+
+ equal(router.get('location.path'), "");
+
+ var appController = container.lookup('controller:application');
+ expectedReplaceURL = "/?commit_by=igor_seb";
+ setAndFlush(appController, 'commitBy', 'igor_seb');
+});
+
QUnit.test("An explicit replace:false on a changed QP always wins and causes a pushState", function() {
expect(3);
App.ApplicationController = Ember.Controller.extend({
@@ -700,6 +1067,35 @@ QUnit.test("An explicit replace:false on a changed QP always wins and causes a p
Ember.run(appController, 'setProperties', { alex: 'sriracha' });
});
+QUnit.test("An explicit replace:false on a changed QP always wins and causes a pushState even when configuration is all on the route", function() {
+ expect(3);
+
+ App.ApplicationRoute = Ember.Route.extend({
+ queryParams: {
+ alex: {
+ replace: true,
+ defaultValue: 'matchneer'
+ },
+ steely: {
+ replace: false,
+ defaultValue: 'dan'
+ }
+ }
+ });
+
+ bootApplication();
+
+ var appController = container.lookup('controller:application');
+ expectedPushURL = "/?alex=wallace&steely=jan";
+ Ember.run(appController, 'setProperties', { alex: 'wallace', steely: 'jan' });
+
+ expectedPushURL = "/?alex=wallace&steely=fran";
+ Ember.run(appController, 'setProperties', { steely: 'fran' });
+
+ expectedReplaceURL = "/?alex=sriracha&steely=fran";
+ Ember.run(appController, 'setProperties', { alex: 'sriracha' });
+});
+
QUnit.test("can opt into full transition by setting refreshModel in route queryParams when transitioning from child to parent", function() {
Ember.TEMPLATES.parent = compile('{{outlet}}');
Ember.TEMPLATES['parent/child'] = compile("{{link-to 'Parent' 'parent' (query-params foo='change') id='parent-link'}}");
@@ -739,6 +1135,41 @@ QUnit.test("can opt into full transition by setting refreshModel in route queryP
equal(parentModelCount, 2);
});
+QUnit.test("can opt into full transition by setting refreshModel in route queryParams when transitioning from child to parent when all configuration is on route", function() {
+ Ember.TEMPLATES.parent = compile('{{outlet}}');
+ Ember.TEMPLATES['parent/child'] = compile("{{link-to 'Parent' 'parent' (query-params foo='change') id='parent-link'}}");
+
+ App.Router.map(function() {
+ this.resource('parent', function() {
+ this.route('child');
+ });
+ });
+
+ var parentModelCount = 0;
+ App.ParentRoute = Ember.Route.extend({
+ model() {
+ parentModelCount++;
+ },
+ queryParams: {
+ foo: {
+ refreshModel: true,
+ defaultValue: 'abc'
+ }
+ }
+ });
+
+ startingURL = '/parent/child?foo=lol';
+ bootApplication();
+
+ equal(parentModelCount, 1);
+
+ container.lookup('controller:parent');
+
+ Ember.run(Ember.$('#parent-link'), 'click');
+
+ equal(parentModelCount, 2);
+});
+
QUnit.test("Use Ember.get to retrieve query params 'replace' configuration", function() {
expect(2);
App.ApplicationController = Ember.Controller.extend({
@@ -843,6 +1274,27 @@ QUnit.test("URL transitions that remove QPs still register as QP changes", funct
equal(indexController.get('omg'), 'lol');
});
+QUnit.test("URL transitions that remove QPs still register as QP changes when configuration lives on the route", function() {
+ expect(2);
+
+ App.IndexRoute = Ember.Route.extend({
+ queryParams: {
+ omg: {
+ defaultValue: 'lol'
+ }
+ }
+ });
+
+ startingURL = "/?omg=borf";
+ bootApplication();
+
+ var indexController = container.lookup('controller:index');
+ equal(indexController.get('omg'), 'borf');
+ Ember.run(router, 'transitionTo', '/');
+ equal(indexController.get('omg'), 'lol');
+});
+
+
QUnit.test("Subresource naming style is supported", function() {
Router.map(function() {
@@ -874,6 +1326,41 @@ QUnit.test("Subresource naming style is supported", function() {
equal(router.get('location.path'), "/abcdef/zoo?bar=456&foo=123");
});
+QUnit.test("Subresource naming style is supported when configuration is all on the route", function() {
+
+ Router.map(function() {
+ this.resource('abc.def', { path: '/abcdef' }, function() {
+ this.route('zoo');
+ });
+ });
+
+ Ember.TEMPLATES.application = compile("{{link-to 'A' 'abc.def' (query-params foo='123') id='one'}}{{link-to 'B' 'abc.def.zoo' (query-params foo='123' bar='456') id='two'}}{{outlet}}");
+
+ App.AbcDefRoute = Ember.Route.extend({
+ queryParams: {
+ foo: 'lol'
+ }
+ });
+
+ App.AbcDefZooRoute = Ember.Route.extend({
+ queryParams: {
+ bar: {
+ defaultValue: 'haha'
+ }
+ }
+ });
+
+ bootApplication();
+ equal(router.get('location.path'), "");
+ equal(Ember.$('#one').attr('href'), "/abcdef?foo=123");
+ equal(Ember.$('#two').attr('href'), "/abcdef/zoo?bar=456&foo=123");
+
+ Ember.run(Ember.$('#one'), 'click');
+ equal(router.get('location.path'), "/abcdef?foo=123");
+ Ember.run(Ember.$('#two'), 'click');
+ equal(router.get('location.path'), "/abcdef/zoo?bar=456&foo=123");
+});
+
QUnit.test("transitionTo supports query params", function() {
App.IndexController = Ember.Controller.extend({
queryParams: ['foo'],
@@ -894,6 +1381,29 @@ QUnit.test("transitionTo supports query params", function() {
equal(router.get('location.path'), "/?foo=false", "shorhand supported (bool)");
});
+QUnit.test("transitionTo supports query params when configuration occurs on the route", function() {
+ App.IndexRoute = Ember.Route.extend({
+ queryParams: {
+ foo: {
+ defaultValue: 'lol'
+ }
+ }
+ });
+
+ bootApplication();
+
+ equal(router.get('location.path'), "");
+
+ Ember.run(router, 'transitionTo', { queryParams: { foo: "borf" } });
+ equal(router.get('location.path'), "/?foo=borf", "shorthand supported");
+ Ember.run(router, 'transitionTo', { queryParams: { 'index:foo': "blaf" } });
+ equal(router.get('location.path'), "/?foo=blaf", "longform supported");
+ Ember.run(router, 'transitionTo', { queryParams: { 'index:foo': false } });
+ equal(router.get('location.path'), "/?foo=false", "longform supported (bool)");
+ Ember.run(router, 'transitionTo', { queryParams: { foo: false } });
+ equal(router.get('location.path'), "/?foo=false", "shorhand supported (bool)");
+});
+
QUnit.test("transitionTo supports query params (multiple)", function() {
App.IndexController = Ember.Controller.extend({
queryParams: ['foo', 'bar'],
@@ -915,6 +1425,32 @@ QUnit.test("transitionTo supports query params (multiple)", function() {
equal(router.get('location.path'), "/?foo=false", "shorhand supported (bool)");
});
+QUnit.test("transitionTo supports query params (multiple) when configuration occurs on the route", function() {
+ App.IndexRoute = Ember.Route.extend({
+ queryParams: {
+ foo: {
+ defaultValue: 'lol'
+ },
+ bar: {
+ defaultValue: 'wat'
+ }
+ }
+ });
+
+ bootApplication();
+
+ equal(router.get('location.path'), "");
+
+ Ember.run(router, 'transitionTo', { queryParams: { foo: "borf" } });
+ equal(router.get('location.path'), "/?foo=borf", "shorthand supported");
+ Ember.run(router, 'transitionTo', { queryParams: { 'index:foo': "blaf" } });
+ equal(router.get('location.path'), "/?foo=blaf", "longform supported");
+ Ember.run(router, 'transitionTo', { queryParams: { 'index:foo': false } });
+ equal(router.get('location.path'), "/?foo=false", "longform supported (bool)");
+ Ember.run(router, 'transitionTo', { queryParams: { foo: false } });
+ equal(router.get('location.path'), "/?foo=false", "shorhand supported (bool)");
+});
+
QUnit.test("setting controller QP to empty string doesn't generate null in URL", function() {
expect(1);
App.IndexController = Ember.Controller.extend({
@@ -929,6 +1465,23 @@ QUnit.test("setting controller QP to empty string doesn't generate null in URL",
setAndFlush(controller, 'foo', '');
});
+QUnit.test("setting QP to empty string doesn't generate null in URL", function() {
+ expect(1);
+ App.IndexRoute = Ember.Route.extend({
+ queryParams: {
+ foo: {
+ defaultValue: "123"
+ }
+ }
+ });
+
+ bootApplication();
+ var controller = container.lookup('controller:index');
+
+ expectedPushURL = "/?foo=";
+ setAndFlush(controller, 'foo', '');
+});
+
QUnit.test("A default boolean value deserializes QPs as booleans rather than strings", function() {
App.IndexController = Ember.Controller.extend({
queryParams: ['foo'],
@@ -951,6 +1504,28 @@ QUnit.test("A default boolean value deserializes QPs as booleans rather than str
equal(controller.get('foo'), false);
});
+QUnit.test("A default boolean value deserializes QPs as booleans rather than strings when configuration occurs on the route", function() {
+ App.IndexRoute = Ember.Route.extend({
+ queryParams: {
+ foo: {
+ defaultValue: false
+ }
+ },
+ model(params) {
+ equal(params.foo, true, "model hook received foo as boolean true");
+ }
+ });
+
+ startingURL = "/?foo=true";
+ bootApplication();
+
+ var controller = container.lookup('controller:index');
+ equal(controller.get('foo'), true);
+
+ handleURL('/?foo=false');
+ equal(controller.get('foo'), false);
+});
+
QUnit.test("Query param without value are empty string", function() {
App.IndexController = Ember.Controller.extend({
queryParams: ['foo'],
@@ -964,10 +1539,26 @@ QUnit.test("Query param without value are empty string", function() {
equal(controller.get('foo'), "");
});
-QUnit.test("Array query params can be set", function() {
- Router.map(function() {
- this.route("home", { path: '/' });
- });
+QUnit.test("Query param without value are empty string when configuration occurs on the route", function() {
+ App.IndexRoute = Ember.Route.extend({
+ queryParams: {
+ foo: {
+ defaultValue: ''
+ }
+ }
+ });
+
+ startingURL = "/?foo=";
+ bootApplication();
+
+ var controller = container.lookup('controller:index');
+ equal(controller.get('foo'), "");
+});
+
+QUnit.test("Array query params can be set", function() {
+ Router.map(function() {
+ this.route("home", { path: '/' });
+ });
App.HomeController = Ember.Controller.extend({
queryParams: ['foo'],
@@ -986,6 +1577,31 @@ QUnit.test("Array query params can be set", function() {
equal(router.get('location.path'), "/?foo=%5B3%2C4%5D");
});
+QUnit.test("Array query params can be set when configured on the route", function() {
+ Router.map(function() {
+ this.route("home", { path: '/' });
+ });
+
+ App.HomeRoute = Ember.Route.extend({
+ queryParams: {
+ foo: {
+ defaultValue: []
+ }
+ }
+ });
+
+ bootApplication();
+
+ var controller = container.lookup('controller:home');
+
+ setAndFlush(controller, 'foo', [1,2]);
+
+ equal(router.get('location.path'), "/?foo=%5B1%2C2%5D");
+
+ setAndFlush(controller, 'foo', [3,4]);
+ equal(router.get('location.path'), "/?foo=%5B3%2C4%5D");
+});
+
QUnit.test("(de)serialization: arrays", function() {
App.IndexController = Ember.Controller.extend({
queryParams: ['foo'],
@@ -1004,6 +1620,27 @@ QUnit.test("(de)serialization: arrays", function() {
equal(router.get('location.path'), "/?foo=%5B%5D", "longform supported");
});
+QUnit.test("(de)serialization: arrays when configuration occurs on the route", function() {
+ App.IndexRoute = Ember.Route.extend({
+ queryParams: {
+ foo: {
+ defaultValue: [1]
+ }
+ }
+ });
+
+ bootApplication();
+
+ equal(router.get('location.path'), "");
+
+ Ember.run(router, 'transitionTo', { queryParams: { foo: [2,3] } });
+ equal(router.get('location.path'), "/?foo=%5B2%2C3%5D", "shorthand supported");
+ Ember.run(router, 'transitionTo', { queryParams: { 'index:foo': [4,5] } });
+ equal(router.get('location.path'), "/?foo=%5B4%2C5%5D", "longform supported");
+ Ember.run(router, 'transitionTo', { queryParams: { foo: [] } });
+ equal(router.get('location.path'), "/?foo=%5B%5D", "longform supported");
+});
+
QUnit.test("Url with array query param sets controller property to array", function() {
App.IndexController = Ember.Controller.extend({
queryParams: ['foo'],
@@ -1017,6 +1654,40 @@ QUnit.test("Url with array query param sets controller property to array", funct
deepEqual(controller.get('foo'), ["1","2","3"]);
});
+QUnit.test("Url with array query param sets controller property to array when configuration occurs on the route", function() {
+ App.IndexRoute = Ember.Route.extend({
+ queryParams: {
+ foo: {
+ defaultValue: ''
+ }
+ }
+ });
+
+ startingURL = "/?foo[]=1&foo[]=2&foo[]=3";
+ bootApplication();
+
+ var controller = container.lookup('controller:index');
+ deepEqual(controller.get('foo'), ["1","2","3"]);
+});
+
+QUnit.test("Url with array query param sets controller property to array when configuration occurs on the route and there is still a controller", function() {
+ App.IndexController = Ember.Controller.extend();
+
+ App.IndexRoute = Ember.Route.extend({
+ queryParams: {
+ foo: {
+ defaultValue: ''
+ }
+ }
+ });
+
+ startingURL = "/?foo[]=1&foo[]=2&foo[]=3";
+ bootApplication();
+
+ var controller = container.lookup('controller:index');
+ deepEqual(controller.get('foo'), ["1","2","3"]);
+});
+
QUnit.test("Array query params can be pushed/popped", function() {
Router.map(function() {
this.route("home", { path: '/' });
@@ -1059,6 +1730,53 @@ QUnit.test("Array query params can be pushed/popped", function() {
deepEqual(controller.foo, ['lol', 1]);
});
+QUnit.test("Array query params can be pushed/popped when configuration occurs on the route but there is still a controller", function() {
+ Router.map(function() {
+ this.route("home", { path: '/' });
+ });
+
+ App.HomeController = Ember.Controller.extend({
+ foo: Ember.A([])
+ });
+
+ App.HomeRoute = Ember.Route.extend({
+ queryParams: {
+ foo: {}
+ }
+ });
+
+ bootApplication();
+
+ equal(router.get('location.path'), "");
+
+ var controller = container.lookup('controller:home');
+
+ Ember.run(controller.foo, 'pushObject', 1);
+ equal(router.get('location.path'), "/?foo=%5B1%5D");
+ deepEqual(controller.foo, [1]);
+ Ember.run(controller.foo, 'popObject');
+ equal(router.get('location.path'), "/");
+ deepEqual(controller.foo, []);
+ Ember.run(controller.foo, 'pushObject', 1);
+ equal(router.get('location.path'), "/?foo=%5B1%5D");
+ deepEqual(controller.foo, [1]);
+ Ember.run(controller.foo, 'popObject');
+ equal(router.get('location.path'), "/");
+ deepEqual(controller.foo, []);
+ Ember.run(controller.foo, 'pushObject', 1);
+ equal(router.get('location.path'), "/?foo=%5B1%5D");
+ deepEqual(controller.foo, [1]);
+ Ember.run(controller.foo, 'pushObject', 2);
+ equal(router.get('location.path'), "/?foo=%5B1%2C2%5D");
+ deepEqual(controller.foo, [1, 2]);
+ Ember.run(controller.foo, 'popObject');
+ equal(router.get('location.path'), "/?foo=%5B1%5D");
+ deepEqual(controller.foo, [1]);
+ Ember.run(controller.foo, 'unshiftObject', 'lol');
+ equal(router.get('location.path'), "/?foo=%5B%22lol%22%2C1%5D");
+ deepEqual(controller.foo, ['lol', 1]);
+});
+
QUnit.test("Overwriting with array with same content shouldn't refire update", function() {
expect(3);
var modelCount = 0;
@@ -1087,6 +1805,36 @@ QUnit.test("Overwriting with array with same content shouldn't refire update", f
equal(router.get('location.path'), "");
});
+QUnit.test("Overwriting with array with same content shouldn't refire update when configuration occurs on router but there is still a controller", function() {
+ expect(3);
+ var modelCount = 0;
+
+ Router.map(function() {
+ this.route("home", { path: '/' });
+ });
+
+ App.HomeRoute = Ember.Route.extend({
+ queryParams: {
+ foo: {}
+ },
+ model() {
+ modelCount++;
+ }
+ });
+
+ App.HomeController = Ember.Controller.extend({
+ foo: Ember.A([1])
+ });
+
+ bootApplication();
+
+ equal(modelCount, 1);
+ var controller = container.lookup('controller:home');
+ setAndFlush(controller, 'model', Ember.A([1]));
+ equal(modelCount, 1);
+ equal(router.get('location.path'), "");
+});
+
QUnit.test("Defaulting to params hash as the model should not result in that params object being watched", function() {
expect(1);
@@ -1137,6 +1885,30 @@ QUnit.test("A child of a resource route still defaults to parent route's model e
bootApplication();
});
+QUnit.test("A child of a resource route still defaults to parent route's model even if the child route has a query param when configuration occurs on the router", function() {
+ expect(1);
+
+ App.IndexRoute = Ember.Route.extend({
+ queryParams: {
+ woot: {}
+ }
+ });
+
+ App.ApplicationRoute = Ember.Route.extend({
+ model(p, trans) {
+ return { woot: true };
+ }
+ });
+
+ App.IndexRoute = Ember.Route.extend({
+ setupController(controller, model) {
+ deepEqual(withoutMeta(model), { woot: true }, "index route inherited model route from parent route");
+ }
+ });
+
+ bootApplication();
+});
+
QUnit.test("opting into replace does not affect transitions between routes", function() {
expect(5);
Ember.TEMPLATES.application = compile(
@@ -1150,107 +1922,524 @@ QUnit.test("opting into replace does not affect transitions between routes", fun
this.route('bar');
});
- App.BarController = Ember.Controller.extend({
- queryParams: ['raytiley'],
- raytiley: 'israd'
- });
+ App.BarController = Ember.Controller.extend({
+ queryParams: ['raytiley'],
+ raytiley: 'israd'
+ });
+
+ App.BarRoute = Ember.Route.extend({
+ queryParams: {
+ raytiley: {
+ replace: true
+ }
+ }
+ });
+
+ bootApplication();
+ var controller = container.lookup('controller:bar');
+
+ expectedPushURL = '/foo';
+ Ember.run(Ember.$('#foo-link'), 'click');
+
+ expectedPushURL = '/bar';
+ Ember.run(Ember.$('#bar-no-qp-link'), 'click');
+
+ expectedReplaceURL = '/bar?raytiley=woot';
+ setAndFlush(controller, 'raytiley', 'woot');
+
+ expectedPushURL = '/foo';
+ Ember.run(Ember.$('#foo-link'), 'click');
+
+ expectedPushURL = '/bar?raytiley=isthebest';
+ Ember.run(Ember.$('#bar-link'), 'click');
+});
+
+QUnit.test("opting into replace does not affect transitions between routes when configuration occurs on the route", function() {
+ expect(5);
+ Ember.TEMPLATES.application = compile(
+ "{{link-to 'Foo' 'foo' id='foo-link'}}" +
+ "{{link-to 'Bar' 'bar' id='bar-no-qp-link'}}" +
+ "{{link-to 'Bar' 'bar' (query-params raytiley='isthebest') id='bar-link'}}" +
+ "{{outlet}}"
+ );
+ App.Router.map(function() {
+ this.route('foo');
+ this.route('bar');
+ });
+
+ App.BarRoute = Ember.Route.extend({
+ queryParams: {
+ raytiley: {
+ replace: true,
+ defaultValue: 'israd'
+ }
+ }
+ });
+
+ bootApplication();
+ var controller = container.lookup('controller:bar');
+
+ expectedPushURL = '/foo';
+ Ember.run(Ember.$('#foo-link'), 'click');
+
+ expectedPushURL = '/bar';
+ Ember.run(Ember.$('#bar-no-qp-link'), 'click');
+
+ expectedReplaceURL = '/bar?raytiley=woot';
+ setAndFlush(controller, 'raytiley', 'woot');
+
+ expectedPushURL = '/foo';
+ Ember.run(Ember.$('#foo-link'), 'click');
+
+ expectedPushURL = '/bar?raytiley=isthebest';
+ Ember.run(Ember.$('#bar-link'), 'click');
+});
+
+QUnit.test("Undefined isn't deserialized into a string", function() {
+ expect(3);
+ Router.map(function() {
+ this.route("example");
+ });
+
+ Ember.TEMPLATES.application = compile("{{link-to 'Example' 'example' id='the-link'}}");
+
+ App.ExampleController = Ember.Controller.extend({
+ queryParams: ['foo']
+ // uncommon to not support default value, but should assume undefined.
+ });
+
+ App.ExampleRoute = Ember.Route.extend({
+ model(params) {
+ deepEqual(params, { foo: undefined });
+ }
+ });
+
+ bootApplication();
+
+ var $link = Ember.$('#the-link');
+ equal($link.attr('href'), "/example");
+ Ember.run($link, 'click');
+
+ var controller = container.lookup('controller:example');
+ equal(get(controller, 'foo'), undefined);
+});
+
+QUnit.test("Undefined isn't deserialized into a string when configuration occurs on the route", function() {
+ expect(3);
+ Router.map(function() {
+ this.route("example");
+ });
+
+ Ember.TEMPLATES.application = compile("{{link-to 'Example' 'example' id='the-link'}}");
+
+ App.ExampleRoute = Ember.Route.extend({
+ queryParams: {
+ // uncommon to not support default value, but should assume undefined.
+ foo: {
+ defaultValue: undefined
+ }
+ },
+ model(params) {
+ deepEqual(params, { foo: undefined });
+ }
+ });
+
+ bootApplication();
+
+ var $link = Ember.$('#the-link');
+ equal($link.attr('href'), "/example");
+ Ember.run($link, 'click');
+
+ var controller = container.lookup('controller:example');
+ equal(get(controller, 'foo'), undefined);
+});
+
+QUnit.test("query params have been set by the time setupController is called", function() {
+ expect(1);
+
+ App.ApplicationController = Ember.Controller.extend({
+ queryParams: ['foo'],
+ foo: "wat"
+ });
+
+ App.ApplicationRoute = Ember.Route.extend({
+ setupController(controller) {
+ equal(controller.get('foo'), 'YEAH', "controller's foo QP property set before setupController called");
+ }
+ });
+
+ startingURL = '/?foo=YEAH';
+ bootApplication();
+});
+
+QUnit.test("query params have been set by the time setupController is called when configuration occurs on the router", function() {
+ expect(1);
+
+ App.ApplicationRoute = Ember.Route.extend({
+ queryParams: {
+ foo: {
+ defaultValue: 'wat'
+ }
+ },
+ setupController(controller) {
+ equal(controller.get('foo'), 'YEAH', "controller's foo QP property set before setupController called");
+ }
+ });
+
+ startingURL = '/?foo=YEAH';
+ bootApplication();
+});
+
+QUnit.test("query params have been set by the time setupController is called when configuration occurs on the router and there is still a controller", function() {
+ expect(1);
+
+ App.ApplicationController = Ember.Controller.extend();
+
+ App.ApplicationRoute = Ember.Route.extend({
+ queryParams: {
+ foo: {
+ defaultValue: 'wat'
+ }
+ },
+ setupController(controller) {
+ equal(controller.get('foo'), 'YEAH', "controller's foo QP property set before setupController called");
+ }
+ });
+
+ startingURL = '/?foo=YEAH';
+ bootApplication();
+});
+
+var testParamlessLinks = function(routeName) {
+ QUnit.test("param-less links in an app booted with query params in the URL don't reset the query params: " + routeName, function() {
+ expect(1);
+
+ Ember.TEMPLATES[routeName] = compile("{{link-to 'index' 'index' id='index-link'}}");
+
+ App[capitalize(routeName) + "Controller"] = Ember.Controller.extend({
+ queryParams: ['foo'],
+ foo: "wat"
+ });
+
+ startingURL = '/?foo=YEAH';
+ bootApplication();
+
+ equal(Ember.$('#index-link').attr('href'), '/?foo=YEAH');
+ });
+};
+
+testParamlessLinks('application');
+testParamlessLinks('index');
+
+var testParamlessLinksWithRouteConfig = function(routeName) {
+ QUnit.test("param-less links in an app booted with query params in the URL don't reset the query params: " + routeName, function() {
+ expect(1);
+
+ Ember.TEMPLATES[routeName] = compile("{{link-to 'index' 'index' id='index-link'}}");
+
+ App[capitalize(routeName) + "Route"] = Ember.Route.extend({
+ queryParams: {
+ foo: {
+ defaultValue: "wat"
+ }
+ }
+ });
+
+ startingURL = '/?foo=YEAH';
+ bootApplication();
+
+ equal(Ember.$('#index-link').attr('href'), '/?foo=YEAH');
+ });
+};
+
+testParamlessLinksWithRouteConfig('application');
+testParamlessLinksWithRouteConfig('index');
+
+QUnit.module("Model Dep Query Params", {
+ setup() {
+ sharedSetup();
+
+ App.Router.map(function() {
+ this.resource('article', { path: '/a/:id' }, function() {
+ this.resource('comments');
+ });
+ });
+
+ var articles = this.articles = Ember.A([{ id: 'a-1' }, { id: 'a-2' }, { id: 'a-3' }]);
+
+ App.ApplicationController = Ember.Controller.extend({
+ articles: this.articles
+ });
+
+ var self = this;
+ App.ArticleRoute = Ember.Route.extend({
+ model(params) {
+ if (self.expectedModelHookParams) {
+ deepEqual(params, self.expectedModelHookParams, "the ArticleRoute model hook received the expected merged dynamic segment + query params hash");
+ self.expectedModelHookParams = null;
+ }
+ return articles.findProperty('id', params.id);
+ }
+ });
+
+ App.ArticleController = Ember.Controller.extend({
+ queryParams: ['q', 'z'],
+ q: 'wat',
+ z: 0
+ });
+
+ App.CommentsController = Ember.Controller.extend({
+ queryParams: 'page',
+ page: 1
+ });
+
+ Ember.TEMPLATES.application = compile("{{#each a in articles}} {{link-to 'Article' 'article' a id=a.id}} {{/each}} {{outlet}}");
+
+ this.boot = function() {
+ bootApplication();
+
+ self.$link1 = Ember.$('#a-1');
+ self.$link2 = Ember.$('#a-2');
+ self.$link3 = Ember.$('#a-3');
+
+ equal(self.$link1.attr('href'), '/a/a-1');
+ equal(self.$link2.attr('href'), '/a/a-2');
+ equal(self.$link3.attr('href'), '/a/a-3');
+
+ self.controller = container.lookup('controller:article');
+ };
+ },
+
+ teardown() {
+ sharedTeardown();
+ ok(!this.expectedModelHookParams, "there should be no pending expectation of expected model hook params");
+ }
+});
+
+QUnit.test("query params have 'model' stickiness by default", function() {
+ this.boot();
+
+ Ember.run(this.$link1, 'click');
+ equal(router.get('location.path'), '/a/a-1');
+
+ setAndFlush(this.controller, 'q', 'lol');
+
+ equal(this.$link1.attr('href'), '/a/a-1?q=lol');
+ equal(this.$link2.attr('href'), '/a/a-2');
+ equal(this.$link3.attr('href'), '/a/a-3');
+
+ Ember.run(this.$link2, 'click');
+
+ equal(this.controller.get('q'), 'wat');
+ equal(this.controller.get('z'), 0);
+ deepEqual(withoutMeta(this.controller.get('model')), { id: 'a-2' });
+ equal(this.$link1.attr('href'), '/a/a-1?q=lol');
+ equal(this.$link2.attr('href'), '/a/a-2');
+ equal(this.$link3.attr('href'), '/a/a-3');
+});
+
+QUnit.test("query params have 'model' stickiness by default (url changes)", function() {
+ this.boot();
+
+ this.expectedModelHookParams = { id: 'a-1', q: 'lol', z: 0 };
+ handleURL('/a/a-1?q=lol');
+
+ deepEqual(withoutMeta(this.controller.get('model')), { id: 'a-1' });
+ equal(this.controller.get('q'), 'lol');
+ equal(this.controller.get('z'), 0);
+ equal(this.$link1.attr('href'), '/a/a-1?q=lol');
+ equal(this.$link2.attr('href'), '/a/a-2');
+ equal(this.$link3.attr('href'), '/a/a-3');
+
+ this.expectedModelHookParams = { id: 'a-2', q: 'lol', z: 0 };
+ handleURL('/a/a-2?q=lol');
+
+ deepEqual(withoutMeta(this.controller.get('model')), { id: 'a-2' }, "controller's model changed to a-2");
+ equal(this.controller.get('q'), 'lol');
+ equal(this.controller.get('z'), 0);
+ equal(this.$link1.attr('href'), '/a/a-1?q=lol');
+ equal(this.$link2.attr('href'), '/a/a-2?q=lol'); // fail
+ equal(this.$link3.attr('href'), '/a/a-3');
+
+ this.expectedModelHookParams = { id: 'a-3', q: 'lol', z: 123 };
+ handleURL('/a/a-3?q=lol&z=123');
+
+ equal(this.controller.get('q'), 'lol');
+ equal(this.controller.get('z'), 123);
+ equal(this.$link1.attr('href'), '/a/a-1?q=lol');
+ equal(this.$link2.attr('href'), '/a/a-2?q=lol');
+ equal(this.$link3.attr('href'), '/a/a-3?q=lol&z=123');
+});
+
+
+QUnit.test("query params have 'model' stickiness by default (params-based transitions)", function() {
+ Ember.TEMPLATES.application = compile("{{#each a in articles}} {{link-to 'Article' 'article' a.id id=a.id}} {{/each}}");
+
+ this.boot();
+
+ this.expectedModelHookParams = { id: 'a-1', q: 'wat', z: 0 };
+ Ember.run(router, 'transitionTo', 'article', 'a-1');
+
+ deepEqual(withoutMeta(this.controller.get('model')), { id: 'a-1' });
+ equal(this.controller.get('q'), 'wat');
+ equal(this.controller.get('z'), 0);
+ equal(this.$link1.attr('href'), '/a/a-1');
+ equal(this.$link2.attr('href'), '/a/a-2');
+ equal(this.$link3.attr('href'), '/a/a-3');
+
+ this.expectedModelHookParams = { id: 'a-2', q: 'lol', z: 0 };
+ Ember.run(router, 'transitionTo', 'article', 'a-2', { queryParams: { q: 'lol' } });
+
+ deepEqual(withoutMeta(this.controller.get('model')), { id: 'a-2' });
+ equal(this.controller.get('q'), 'lol');
+ equal(this.controller.get('z'), 0);
+ equal(this.$link1.attr('href'), '/a/a-1');
+ equal(this.$link2.attr('href'), '/a/a-2?q=lol');
+ equal(this.$link3.attr('href'), '/a/a-3');
+
+ this.expectedModelHookParams = { id: 'a-3', q: 'hay', z: 0 };
+ Ember.run(router, 'transitionTo', 'article', 'a-3', { queryParams: { q: 'hay' } });
+
+ deepEqual(withoutMeta(this.controller.get('model')), { id: 'a-3' });
+ equal(this.controller.get('q'), 'hay');
+ equal(this.controller.get('z'), 0);
+ equal(this.$link1.attr('href'), '/a/a-1');
+ equal(this.$link2.attr('href'), '/a/a-2?q=lol');
+ equal(this.$link3.attr('href'), '/a/a-3?q=hay');
+
+ this.expectedModelHookParams = { id: 'a-2', q: 'lol', z: 1 };
+ Ember.run(router, 'transitionTo', 'article', 'a-2', { queryParams: { z: 1 } });
+
+ deepEqual(withoutMeta(this.controller.get('model')), { id: 'a-2' });
+ equal(this.controller.get('q'), 'lol');
+ equal(this.controller.get('z'), 1);
+ equal(this.$link1.attr('href'), '/a/a-1');
+ equal(this.$link2.attr('href'), '/a/a-2?q=lol&z=1');
+ equal(this.$link3.attr('href'), '/a/a-3?q=hay');
+});
+
+QUnit.test("'controller' stickiness shares QP state between models", function() {
+ App.ArticleController.reopen({
+ queryParams: { q: { scope: 'controller' } }
+ });
+
+ this.boot();
+
+ Ember.run(this.$link1, 'click');
+ equal(router.get('location.path'), '/a/a-1');
+
+ setAndFlush(this.controller, 'q', 'lol');
+
+ equal(this.$link1.attr('href'), '/a/a-1?q=lol');
+ equal(this.$link2.attr('href'), '/a/a-2?q=lol');
+ equal(this.$link3.attr('href'), '/a/a-3?q=lol');
+
+ Ember.run(this.$link2, 'click');
- App.BarRoute = Ember.Route.extend({
- queryParams: {
- raytiley: {
- replace: true
- }
- }
- });
+ equal(this.controller.get('q'), 'lol');
+ equal(this.controller.get('z'), 0);
+ deepEqual(withoutMeta(this.controller.get('model')), { id: 'a-2' });
- bootApplication();
- var controller = container.lookup('controller:bar');
+ equal(this.$link1.attr('href'), '/a/a-1?q=lol');
+ equal(this.$link2.attr('href'), '/a/a-2?q=lol');
+ equal(this.$link3.attr('href'), '/a/a-3?q=lol');
- expectedPushURL = '/foo';
- Ember.run(Ember.$('#foo-link'), 'click');
+ this.expectedModelHookParams = { id: 'a-3', q: 'haha', z: 123 };
+ handleURL('/a/a-3?q=haha&z=123');
- expectedPushURL = '/bar';
- Ember.run(Ember.$('#bar-no-qp-link'), 'click');
+ deepEqual(withoutMeta(this.controller.get('model')), { id: 'a-3' });
+ equal(this.controller.get('q'), 'haha');
+ equal(this.controller.get('z'), 123);
- expectedReplaceURL = '/bar?raytiley=woot';
- setAndFlush(controller, 'raytiley', 'woot');
+ equal(this.$link1.attr('href'), '/a/a-1?q=haha');
+ equal(this.$link2.attr('href'), '/a/a-2?q=haha');
+ equal(this.$link3.attr('href'), '/a/a-3?q=haha&z=123');
- expectedPushURL = '/foo';
- Ember.run(Ember.$('#foo-link'), 'click');
+ setAndFlush(this.controller, 'q', 'woot');
- expectedPushURL = '/bar?raytiley=isthebest';
- Ember.run(Ember.$('#bar-link'), 'click');
+ equal(this.$link1.attr('href'), '/a/a-1?q=woot');
+ equal(this.$link2.attr('href'), '/a/a-2?q=woot');
+ equal(this.$link3.attr('href'), '/a/a-3?q=woot&z=123');
});
-QUnit.test("Undefined isn't deserialized into a string", function() {
- expect(3);
- Router.map(function() {
- this.route("example");
- });
+QUnit.test("'model' stickiness is scoped to current or first dynamic parent route", function() {
+ this.boot();
- Ember.TEMPLATES.application = compile("{{link-to 'Example' 'example' id='the-link'}}");
+ Ember.run(router, 'transitionTo', 'comments', 'a-1');
- App.ExampleController = Ember.Controller.extend({
- queryParams: ['foo']
- // uncommon to not support default value, but should assume undefined.
- });
+ var commentsCtrl = container.lookup('controller:comments');
+ equal(commentsCtrl.get('page'), 1);
+ equal(router.get('location.path'), '/a/a-1/comments');
- App.ExampleRoute = Ember.Route.extend({
- model(params) {
- deepEqual(params, { foo: undefined });
- }
- });
+ setAndFlush(commentsCtrl, 'page', 2);
+ equal(router.get('location.path'), '/a/a-1/comments?page=2');
- bootApplication();
+ setAndFlush(commentsCtrl, 'page', 3);
+ equal(router.get('location.path'), '/a/a-1/comments?page=3');
- var $link = Ember.$('#the-link');
- equal($link.attr('href'), "/example");
- Ember.run($link, 'click');
+ Ember.run(router, 'transitionTo', 'comments', 'a-2');
+ equal(commentsCtrl.get('page'), 1);
+ equal(router.get('location.path'), '/a/a-2/comments');
- var controller = container.lookup('controller:example');
- equal(get(controller, 'foo'), undefined);
+ Ember.run(router, 'transitionTo', 'comments', 'a-1');
+ equal(commentsCtrl.get('page'), 3);
+ equal(router.get('location.path'), '/a/a-1/comments?page=3');
});
-QUnit.test("query params have been set by the time setupController is called", function() {
- expect(1);
-
- App.ApplicationController = Ember.Controller.extend({
- queryParams: ['foo'],
- foo: "wat"
+QUnit.test("can reset query params using the resetController hook", function() {
+ App.Router.map(function() {
+ this.resource('article', { path: '/a/:id' }, function() {
+ this.resource('comments');
+ });
+ this.route('about');
});
- App.ApplicationRoute = Ember.Route.extend({
- setupController(controller) {
- equal(controller.get('foo'), 'YEAH', "controller's foo QP property set before setupController called");
+ App.ArticleRoute.reopen({
+ resetController(controller, isExiting) {
+ this.controllerFor('comments').set('page', 1);
+ if (isExiting) {
+ controller.set('q', 'imdone');
+ }
}
});
- startingURL = '/?foo=YEAH';
- bootApplication();
-});
+ Ember.TEMPLATES.about = compile("{{link-to 'A' 'comments' 'a-1' id='one'}} {{link-to 'B' 'comments' 'a-2' id='two'}}");
-var testParamlessLinks = function(routeName) {
- QUnit.test("param-less links in an app booted with query params in the URL don't reset the query params: " + routeName, function() {
- expect(1);
+ this.boot();
+ Ember.run(router, 'transitionTo', 'comments', 'a-1');
- Ember.TEMPLATES[routeName] = compile("{{link-to 'index' 'index' id='index-link'}}");
+ var commentsCtrl = container.lookup('controller:comments');
+ equal(commentsCtrl.get('page'), 1);
+ equal(router.get('location.path'), '/a/a-1/comments');
- App[capitalize(routeName) + "Controller"] = Ember.Controller.extend({
- queryParams: ['foo'],
- foo: "wat"
- });
+ setAndFlush(commentsCtrl, 'page', 2);
+ equal(router.get('location.path'), '/a/a-1/comments?page=2');
- startingURL = '/?foo=YEAH';
- bootApplication();
- equal(Ember.$('#index-link').attr('href'), '/?foo=YEAH');
- });
-};
+ Ember.run(router, 'transitionTo', 'comments', 'a-2');
+ equal(commentsCtrl.get('page'), 1);
+ equal(this.controller.get('q'), 'wat');
-testParamlessLinks('application');
-testParamlessLinks('index');
+ Ember.run(router, 'transitionTo', 'comments', 'a-1');
-QUnit.module("Model Dep Query Params", {
+ equal(router.get('location.path'), '/a/a-1/comments');
+ equal(commentsCtrl.get('page'), 1);
+
+ Ember.run(router, 'transitionTo', 'about');
+
+ equal(Ember.$('#one').attr('href'), "/a/a-1/comments?q=imdone");
+ equal(Ember.$('#two').attr('href'), "/a/a-2/comments");
+});
+
+QUnit.test("can unit test without bucket cache", function() {
+ var controller = container.lookup('controller:article');
+ controller._bucketCache = null;
+
+ controller.set('q', "i used to break");
+ equal(controller.get('q'), "i used to break");
+});
+
+QUnit.module("Model Dep Query Params with Route-based configuration", {
setup() {
sharedSetup();
@@ -1268,7 +2457,14 @@ QUnit.module("Model Dep Query Params", {
var self = this;
App.ArticleRoute = Ember.Route.extend({
- queryParams: {},
+ queryParams: {
+ q: {
+ defaultValue: 'wat'
+ },
+ z: {
+ defaultValue: 0
+ }
+ },
model(params) {
if (self.expectedModelHookParams) {
deepEqual(params, self.expectedModelHookParams, "the ArticleRoute model hook received the expected merged dynamic segment + query params hash");
@@ -1278,15 +2474,12 @@ QUnit.module("Model Dep Query Params", {
}
});
- App.ArticleController = Ember.Controller.extend({
- queryParams: ['q', 'z'],
- q: 'wat',
- z: 0
- });
-
- App.CommentsController = Ember.Controller.extend({
- queryParams: 'page',
- page: 1
+ App.CommentsRoute = Ember.Route.extend({
+ queryParams: {
+ page: {
+ defaultValue: 1
+ }
+ }
});
Ember.TEMPLATES.application = compile("{{#each a in articles}} {{link-to 'Article' 'article' a id=a.id}} {{/each}} {{outlet}}");
@@ -1368,7 +2561,6 @@ QUnit.test("query params have 'model' stickiness by default (url changes)", func
equal(this.$link3.attr('href'), '/a/a-3?q=lol&z=123');
});
-
QUnit.test("query params have 'model' stickiness by default (params-based transitions)", function() {
Ember.TEMPLATES.application = compile("{{#each a in articles}} {{link-to 'Article' 'article' a.id id=a.id}} {{/each}}");
@@ -1416,7 +2608,7 @@ QUnit.test("query params have 'model' stickiness by default (params-based transi
});
QUnit.test("'controller' stickiness shares QP state between models", function() {
- App.ArticleController.reopen({
+ App.ArticleRoute.reopen({
queryParams: { q: { scope: 'controller' } }
});
@@ -1528,14 +2720,6 @@ QUnit.test("can reset query params using the resetController hook", function() {
equal(Ember.$('#two').attr('href'), "/a/a-2/comments");
});
-QUnit.test("can unit test without bucket cache", function() {
- var controller = container.lookup('controller:article');
- controller._bucketCache = null;
-
- controller.set('q', "i used to break");
- equal(controller.get('q'), "i used to break");
-});
-
QUnit.module("Query Params - overlapping query param property names", {
setup() {
sharedSetup();
@@ -1647,3 +2831,100 @@ QUnit.test("Support shared but overridable mixin pattern", function() {
equal(parentController.get('page'), 2);
equal(parentChildController.get('page'), 2);
});
+
+QUnit.module("Query Params - overlapping query param property names when configured on the route", {
+ setup() {
+ sharedSetup();
+
+ App.Router.map(function() {
+ this.resource('parent', function() {
+ this.route('child');
+ });
+ });
+
+ this.boot = function() {
+ bootApplication();
+ Ember.run(router, 'transitionTo', 'parent.child');
+ };
+ },
+
+ teardown() {
+ sharedTeardown();
+ }
+});
+
+QUnit.test("can remap same-named qp props", function() {
+ App.ParentRoute = Ember.Route.extend({
+ queryParams: {
+ page: {
+ as: 'parentPage',
+ defaultValue: 1
+ }
+ }
+ });
+
+ App.ParentChildRoute = Ember.Route.extend({
+ queryParams: {
+ page: {
+ as: 'childPage',
+ defaultValue: 1
+ }
+ }
+ });
+
+ this.boot();
+
+ equal(router.get('location.path'), '/parent/child');
+
+ var parentController = container.lookup('controller:parent');
+ var parentChildController = container.lookup('controller:parent.child');
+
+ setAndFlush(parentController, 'page', 2);
+ equal(router.get('location.path'), '/parent/child?parentPage=2');
+ setAndFlush(parentController, 'page', 1);
+ equal(router.get('location.path'), '/parent/child');
+
+ setAndFlush(parentChildController, 'page', 2);
+ equal(router.get('location.path'), '/parent/child?childPage=2');
+ setAndFlush(parentChildController, 'page', 1);
+ equal(router.get('location.path'), '/parent/child');
+
+ Ember.run(function() {
+ parentController.set('page', 2);
+ parentChildController.set('page', 2);
+ });
+
+ equal(router.get('location.path'), '/parent/child?childPage=2&parentPage=2');
+
+ Ember.run(function() {
+ parentController.set('page', 1);
+ parentChildController.set('page', 1);
+ });
+
+ equal(router.get('location.path'), '/parent/child');
+});
+
+QUnit.test("query params in the same route hierarchy with the same url key get auto-scoped", function() {
+ App.ParentRoute = Ember.Route.extend({
+ queryParams: {
+ foo: {
+ as: 'shared',
+ defaultValue: 1
+ }
+ }
+ });
+
+ App.ParentChildRoute= Ember.Route.extend({
+ queryParams: {
+ bar: {
+ as: 'shared',
+ defaultValue: 1
+ }
+ }
+ });
+
+ var self = this;
+ expectAssertion(function() {
+ self.boot();
+ }, "You're not allowed to have more than one controller property map to the same query param key, but both `parent:foo` and `parent.child:bar` map to `shared`. You can fix this by mapping one of the controller properties to a different query param key via the `as` config option, e.g. `foo: { as: 'other-foo' }`");
+}); | true |
Other | emberjs | ember.js | 28504216e0cd9b8de8ee4bbb67da6f749addec44.json | Change assertion to deprecation | packages/ember-application/lib/utils/validate-type.js | @@ -17,6 +17,18 @@ export default function validateType(resolvedType, parsedName) {
return;
}
+ // 2.0TODO: Remove this deprecation warning
+ if (parsedName.type === 'service') {
+ Ember.deprecate(
+ "In Ember 2.0 service factories must have an `isServiceFactory` " +
+ `property set to true. You registered ${resolvedType} as a service ` +
+ "factory. Either add the `isServiceFactory` property to this factory or " +
+ "extend from Ember.Service.",
+ resolvedType.isServiceFactory
+ );
+ return;
+ }
+
let [factoryFlag, expectedType] = validationAttributes;
Ember.assert(`Expected ${parsedName.fullName} to resolve to an ${expectedType} but instead it was ${resolvedType}.`, function() { | true |
Other | emberjs | ember.js | 28504216e0cd9b8de8ee4bbb67da6f749addec44.json | Change assertion to deprecation | packages/ember-application/tests/system/dependency_injection/default_resolver_test.js | @@ -178,7 +178,8 @@ QUnit.test("lookup description", function() {
});
QUnit.test("validating resolved objects", function() {
- let types = ['route', 'component', 'view', 'service'];
+ // 2.0TODO: Add service to this list
+ let types = ['route', 'component', 'view'];
// Valid setup
application.FooRoute = Route.extend();
@@ -207,3 +208,16 @@ QUnit.test("validating resolved objects", function() {
}, matcher, `Should assert for ${type}`);
});
});
+
+QUnit.test("deprecation warning for service factories without isServiceFactory property", function() {
+ expectDeprecation(/service factories must have an `isServiceFactory` property/);
+ application.FooService = EmberObject.extend();
+ registry.resolve('service:foo');
+
+});
+
+QUnit.test("no deprecation warning for service factories that extend from Ember.Service", function() {
+ expectNoDeprecation();
+ application.FooService = Service.extend();
+ registry.resolve('service:foo');
+}); | true |
Other | emberjs | ember.js | aa4e4d20a4ce1cd0f58560acffcb2f9f40e6ed47.json | Consolidate duplicated method | packages/ember-metal/lib/chains.js | @@ -288,35 +288,17 @@ ChainNode.prototype = {
}
if (this._parent) {
- this._parent.chainWillChange(this, this._key, 1, events);
+ this._parent.notifyChainChange(this, this._key, 1, events);
}
},
- chainWillChange(chain, path, depth, events) {
+ notifyChainChange(chain, path, depth, events) {
if (this._key) {
path = this._key + '.' + path;
}
if (this._parent) {
- this._parent.chainWillChange(this, path, depth + 1, events);
- } else {
- if (depth > 1) {
- events.push(this.value(), path);
- }
- path = 'this.' + path;
- if (this._paths[path] > 0) {
- events.push(this.value(), path);
- }
- }
- },
-
- chainDidChange(chain, path, depth, events) {
- if (this._key) {
- path = this._key + '.' + path;
- }
-
- if (this._parent) {
- this._parent.chainDidChange(this, path, depth + 1, events);
+ this._parent.notifyChainChange(this, path, depth + 1, events);
} else {
if (depth > 1) {
events.push(this.value(), path);
@@ -364,7 +346,7 @@ ChainNode.prototype = {
// and finally tell parent about my path changing...
if (this._parent) {
- this._parent.chainDidChange(this, this._key, 1, events);
+ this._parent.notifyChainChange(this, this._key, 1, events);
}
}
}; | false |
Other | emberjs | ember.js | 2a726161dd80b3cfd5172922106037bbcc3e4d68.json | Fix basic Fastboot usage. | package.json | @@ -28,7 +28,7 @@
"qunitjs": "^1.16.0",
"route-recognizer": "0.1.5",
"rsvp": "~3.0.6",
- "simple-dom": "^0.1.1",
+ "simple-dom": "^0.2.3",
"testem": "^0.8.0-0"
}
} | true |
Other | emberjs | ember.js | 2a726161dd80b3cfd5172922106037bbcc3e4d68.json | Fix basic Fastboot usage. | packages/ember-htmlbars/lib/node-managers/component-node-manager.js | @@ -252,6 +252,7 @@ export function createComponent(_component, isAngleBracket, _props, renderNode,
props._isAngleBracket = true;
}
+ props.renderer = props.parentView ? props.parentView.renderer : env.container.lookup('renderer:-dom');
let component = _component.create(props);
// for the fallback case | true |
Other | emberjs | ember.js | 2a726161dd80b3cfd5172922106037bbcc3e4d68.json | Fix basic Fastboot usage. | packages/ember-htmlbars/lib/node-managers/view-node-manager.js | @@ -171,6 +171,7 @@ export function createOrUpdateComponent(component, options, createOptions, rende
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');
if (proto.controller !== defaultController || hasSuppliedController) {
delete props._context; | true |
Other | emberjs | ember.js | 2a726161dd80b3cfd5172922106037bbcc3e4d68.json | Fix basic Fastboot usage. | packages/ember-htmlbars/lib/system/bootstrap.js | @@ -74,8 +74,8 @@ function _bootstrap() {
bootstrap(jQuery(document));
}
-function registerComponentLookup(registry) {
- registry.register('component-lookup:main', ComponentLookup);
+function registerComponentLookup(app) {
+ app.registry.register('component-lookup:main', ComponentLookup);
}
/*
@@ -95,9 +95,8 @@ onLoad('Ember.Application', function(Application) {
initialize: environment.hasDOM ? _bootstrap : function() { }
});
- Application.initializer({
+ Application.instanceInitializer({
name: 'registerComponentLookup',
- after: 'domTemplates',
initialize: registerComponentLookup
});
}); | true |
Other | emberjs | ember.js | 2a726161dd80b3cfd5172922106037bbcc3e4d68.json | Fix basic Fastboot usage. | tests/node/app-boot-test.js | @@ -167,7 +167,7 @@ if (canUseInstanceInitializers && canUseApplicationVisit) {
assert.ok(serializer.serialize(view.element).match(/<h1>Hello World<\/h1>/));
});
- QUnit.skip("It is possible to render a view with a nested {{view}} helper in Node", function(assert) {
+ QUnit.test("It is possible to render a view with a nested {{view}} helper in Node", function(assert) {
var View = Ember.Component.extend({
renderer: new Ember.View._Renderer(new DOMHelper(new SimpleDOM.Document())),
layout: compile("<h1>Hello {{#if hasExistence}}{{location}}{{/if}}</h1> <div>{{view bar}}</div>"),
@@ -178,17 +178,15 @@ if (canUseInstanceInitializers && canUseApplicationVisit) {
})
});
- var view = View.create({
- _domHelper: new DOMHelper(new SimpleDOM.Document())
- });
+ var view = View.create();
run(view, view.createElement);
var serializer = new SimpleDOM.HTMLSerializer(SimpleDOM.voidMap);
assert.ok(serializer.serialize(view.element).match(/<h1>Hello World<\/h1> <div><div id="(.*)" class="ember-view"><p>The files are \*inside\* the computer\?\!<\/p><\/div><\/div>/));
});
- QUnit.skip("It is possible to render a view with {{link-to}} in Node", function(assert) {
+ QUnit.test("It is possible to render a view with {{link-to}} in Node", function(assert) {
run(function() {
app = createApplication();
@@ -205,11 +203,11 @@ if (canUseInstanceInitializers && canUseApplicationVisit) {
return app.visit('/').then(function(instance) {
var element = renderToElement(instance);
- assertHTMLMatches(assert, element.firstChild, /^<div id="ember\d+" class="ember-view"><h1><a id="ember\d+" class="ember-view" href="\/photos">Go to photos<\/a><\/h1><\/div>$/);
+ assertHTMLMatches(assert, element.firstChild, /^<div id="ember\d+" class="ember-view"><h1><a id="ember\d+" href="\/photos" class="ember-view">Go to photos<\/a><\/h1><\/div>$/);
});
});
- QUnit.skip("It is possible to render outlets in Node", function(assert) {
+ QUnit.test("It is possible to render outlets in Node", function(assert) {
run(function() {
app = createApplication();
| true |
Other | emberjs | ember.js | 834382ae778be7c1bb24136bc699d2dc90ca2744.json | Add support for inspecting symbols
True Symbols cannot be coerced to a string, and typeof returns
'symbol'. This caused the inspect function treat it as a non-object
(which is technically correct, since it's a new primitive type).
Adds an additional check to ensure the inspected value is not a
Symbol before attempting string coercion. Symbols will fail, and
fall through to the toString() implementation, which is the
desired output. | packages/ember-metal/lib/utils.js | @@ -799,7 +799,8 @@ export function inspect(obj) {
return '[' + obj + ']';
}
// for non objects
- if (typeof obj !== 'object') {
+ var type = typeof obj;
+ if (type !== 'object' && type !== 'symbol') {
return ''+obj;
}
// overridden toString | true |
Other | emberjs | ember.js | 834382ae778be7c1bb24136bc699d2dc90ca2744.json | Add support for inspecting symbols
True Symbols cannot be coerced to a string, and typeof returns
'symbol'. This caused the inspect function treat it as a non-object
(which is technically correct, since it's a new primitive type).
Adds an additional check to ensure the inspected value is not a
Symbol before attempting string coercion. Symbols will fail, and
fall through to the toString() implementation, which is the
desired output. | packages/ember-metal/tests/utils_test.js | @@ -0,0 +1,16 @@
+import { inspect } from 'ember-metal/utils';
+
+QUnit.module("Ember Metal Utils");
+
+QUnit.test("inspect outputs the toString() representation of Symbols", function() {
+ // Symbol is not defined on pre-ES2015 runtimes, so this let's us safely test
+ // for it's existence (where a simple `if (Symbol)` would ReferenceError)
+ let Symbol = Symbol || null;
+
+ if (Symbol) {
+ let symbol = Symbol('test');
+ equal(inspect(symbol), 'Symbol(test)');
+ } else {
+ expect(0);
+ }
+}); | true |
Other | emberjs | ember.js | aa1607b33c5fa56f566f346bb94480437bc0183a.json | Remove unused _yield and _blockArguments | packages/ember-views/lib/views/collection_view.js | @@ -344,32 +344,10 @@ var CollectionView = ContainerView.extend({
view = this.createChildView(itemViewClass, itemViewProps);
- if (Ember.FEATURES.isEnabled('ember-htmlbars-each-with-index')) {
- if (this.blockParams > 1) {
- view._blockArguments = [item, view.getStream('_view.contentIndex')];
- } else if (this.blockParams === 1) {
- view._blockArguments = [item];
- }
- } else {
- if (this.blockParams > 0) {
- view._blockArguments = [item];
- }
- }
-
addedViews.push(view);
}
this.replace(start, 0, addedViews);
-
- if (Ember.FEATURES.isEnabled('ember-htmlbars-each-with-index')) {
- if (this.blockParams > 1) {
- var childViews = this.childViews;
- for (idx = start+added; idx < len; idx++) {
- view = childViews[idx];
- set(view, 'contentIndex', idx);
- }
- }
- }
}
},
| true |
Other | emberjs | ember.js | aa1607b33c5fa56f566f346bb94480437bc0183a.json | Remove unused _yield and _blockArguments | packages/ember-views/lib/views/view.js | @@ -55,8 +55,6 @@ Ember.warn("The VIEW_PRESERVES_CONTEXT flag has been removed and the functionali
*/
Ember.TEMPLATES = {};
-var EMPTY_ARRAY = [];
-
/**
`Ember.View` is the class in Ember responsible for encapsulating templates of
HTML content, combining templates with data to render as sections of a page's
@@ -771,16 +769,6 @@ var View = CoreView.extend(
}
}),
- _yield(context, options, morph) {
- var template = get(this, 'template');
-
- if (template) {
- return template.render(context, options, { contextualElement: morph.contextualElement }).fragment;
- }
- },
-
- _blockArguments: EMPTY_ARRAY,
-
templateForName(name, type) {
if (!name) { return; }
Ember.assert("templateNames are not allowed to contain periods: "+name, name.indexOf('.') === -1); | true |
Other | emberjs | ember.js | 82843abdb5820378fec5501dee280b4d4d0554ea.json | Fix typo in component lookup assert
“canot” => “cannot” | packages/ember-htmlbars/tests/integration/component_lookup_test.js | @@ -36,5 +36,5 @@ QUnit.test('dashless components should not be found', function() {
expectAssertion(function() {
runAppend(view);
- }, /You canot use 'dashless' as a component name. Component names must contain a hyphen./);
+ }, /You cannot use 'dashless' as a component name. Component names must contain a hyphen./);
}); | true |
Other | emberjs | ember.js | 82843abdb5820378fec5501dee280b4d4d0554ea.json | Fix typo in component lookup assert
“canot” => “cannot” | packages/ember-views/lib/component_lookup.js | @@ -7,7 +7,7 @@ export default EmberObject.extend({
var invalidName = ISNT_HELPER_CACHE.get(name);
if (invalidName) {
- Ember.assert(`You canot use '${name}' as a component name. Component names must contain a hyphen.`);
+ Ember.assert(`You cannot use '${name}' as a component name. Component names must contain a hyphen.`);
}
},
| true |
Other | emberjs | ember.js | 0a7c0fce26f11f14f66493758d568c00815569f4.json | Update CHANGELOG for 1.12.0. | CHANGELOG.md | @@ -1,8 +1,32 @@
# Ember Changelog
-### Canary
-
+### 1.12.0 (May 13, 2015)
+
+- [#10874](https://github.com/emberjs/ember.js/pull/10874) Include all files in jspm package.
+- [#10876](https://github.com/emberjs/ember.js/pull/10876) [BUGFIX] Make the `{{component}}` helper deal with dynamically set falsey values.
+- [#10883](https://github.com/emberjs/ember.js/pull/10883) [BUGFIX] Fix `View.prototype.replaceIn` functionality.
+- [#10920](https://github.com/emberjs/ember.js/pull/10920) [BUGFIX] Fix `Component.prototype.layout` so that it can now be set and recompute properly.
+- [#10968](https://github.com/emberjs/ember.js/pull/10968) [BUGFIX] Fix assertion that incorrectly fired on legacy settable computed properties.
+- [CVE-2015-1866] Ember.js XSS Vulnerability With {{view "select"}} Options
- [#3852](https://github.com/emberjs/ember.js/pull/3852) [BREAKING BUGFIX] Do not assume null Ember.get targets always refer to a global
+- [#10200](https://github.com/emberjs/ember.js/pull/10200) Add 'autocomplete' to Ember.Select view
+- [#10464](https://github.com/emberjs/ember.js/pull/10464) Ensure templates were compiled with the current compiler version.
+- [#10494](https://github.com/emberjs/ember.js/pull/10494) Make it easier to write lazy streams.
+- [#10483](https://github.com/emberjs/ember.js/pull/10483) [REFACTOR] Lazily reify router’s location.
+- [#10673](https://github.com/emberjs/ember.js/pull/10673) Remove EachProxy and EachArray from exports.
+- [#10572](https://github.com/emberjs/ember.js/pull/10572) Fix UnrecognizedURLError not being an Error.
+- [#10585](https://github.com/emberjs/ember.js/pull/10585) Deprecate direct use of `Ember.CoreView`.
+- [#10599](https://github.com/emberjs/ember.js/pull/10599) Don’t share view registry across containers.
+- [#10667](https://github.com/emberjs/ember.js/pull/10667) Deprecate `Ember.tryFinally` and `Ember.tryCatchFinally`.
+- [#10668](https://github.com/emberjs/ember.js/pull/10668) Deprecate `Ember.required`.
+- [#10678](https://github.com/emberjs/ember.js/pull/10678) Fix typos in deprecations of unescaped style attribute
+- [#10679](https://github.com/emberjs/ember.js/pull/10679) Ensure docs are not detected for deprecation mixins.
+- [#10672](https://github.com/emberjs/ember.js/pull/10672) Do not export `Ember.Descriptor`.
+- [#10695](https://github.com/emberjs/ember.js/pull/10695) Require that `base` `href` and `embed` `src` are escaped.
+- [#10690](https://github.com/emberjs/ember.js/pull/10690) [BUGFIX canary] Prevent unknown input types from erroring.
+- [#10731](https://github.com/emberjs/ember.js/pull/10731) [FEATURE] Enable `new-computed-syntax` feature. See [emberjs/rfcs#11](https://github.com/emberjs/rfcs/pull/11) for more details.
+- [#10731](https://github.com/emberjs/ember.js/pull/10731) [FEATURE] Enable `ember-application-instance-initializers` feature.
+- [#10731](https://github.com/emberjs/ember.js/pull/10731) [FEATURE] Enable `ember-application-initializer-context` feature.
### 1.11.0 (March 28, 2015)
| false |
Other | emberjs | ember.js | bfc5431e664986f8fb2871a066e50d5de4727f74.json | Fix JSHint error. | packages/ember-views/lib/views/component.js | @@ -9,7 +9,6 @@ import { set } from "ember-metal/property_set";
import isNone from 'ember-metal/is_none';
import { computed } from "ember-metal/computed";
-import { bool } from "ember-metal/computed_macros";
/**
@module ember | false |
Other | emberjs | ember.js | 59011e87a9e1d1b54a4255980f95123d9b6183e4.json | Fix failing node test | tests/node/template-compiler-test.js | @@ -53,7 +53,7 @@ test('allows enabling of features', function() {
templateCompiler._Ember.FEATURES['ember-htmlbars-component-generation'] = true;
templateOutput = templateCompiler.precompile('<some-thing></some-thing>');
- ok(templateOutput.indexOf('["component","some-thing",[],0]') > -1, 'component generation can be enabled');
+ ok(templateOutput.indexOf('["component","<some-thing>",[],0]') > -1, 'component generation can be enabled');
} else {
ok(true, 'cannot test features in feature stripped build');
} | false |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.