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 | 9f8959d4607ba675dec5985412a874aa488d9e58.json | Make promise usage nicer without mixing | packages/ember-runtime/tests/mixins/deferred_test.js | @@ -1,11 +1,11 @@
-module("Ember.Deferred");
+module("Ember.DeferredMixin");
test("can resolve deferred", function() {
var deferred, count = 0;
Ember.run(function() {
- deferred = Ember.Object.createWithMixins(Ember.Deferred);
+ deferred = Ember.Object.createWithMixins(Ember.DeferredMixin);
});
deferred.then(function() {
@@ -28,7 +28,7 @@ test("can reject deferred", function() {
var deferred, count = 0;
Ember.run(function() {
- deferred = Ember.Object.createWithMixins(Ember.Deferred);
+ deferred = Ember.Object.createWithMixins(Ember.DeferredMixin);
});
deferred.then(function() {}, function() {
@@ -51,7 +51,7 @@ test("can resolve with then", function() {
var deferred, count1 = 0 ,count2 = 0;
Ember.run(function() {
- deferred = Ember.Object.createWithMixins(Ember.Deferred);
+ deferred = Ember.Object.createWithMixins(Ember.DeferredMixin);
});
deferred.then(function() {
@@ -77,7 +77,7 @@ test("can reject with then", function() {
var deferred, count1 = 0 ,count2 = 0;
Ember.run(function() {
- deferred = Ember.Object.createWithMixins(Ember.Deferred);
+ deferred = Ember.Object.createWithMixins(Ember.DeferredMixin);
});
deferred.then(function() {
@@ -103,7 +103,7 @@ test("can call resolve multiple times", function() {
var deferred, count = 0;
Ember.run(function() {
- deferred = Ember.Object.createWithMixins(Ember.Deferred);
+ deferred = Ember.Object.createWithMixins(Ember.DeferredMixin);
});
deferred.then(function() {
@@ -127,7 +127,7 @@ test("resolve prevent reject", function() {
var deferred, resolved = false, rejected = false, progress = 0;
Ember.run(function() {
- deferred = Ember.Object.createWithMixins(Ember.Deferred);
+ deferred = Ember.Object.createWithMixins(Ember.DeferredMixin);
});
deferred.then(function() {
@@ -155,7 +155,7 @@ test("reject prevent resolve", function() {
var deferred, resolved = false, rejected = false, progress = 0;
Ember.run(function() {
- deferred = Ember.Object.createWithMixins(Ember.Deferred);
+ deferred = Ember.Object.createWithMixins(Ember.DeferredMixin);
});
deferred.then(function() {
@@ -184,7 +184,7 @@ test("will call callbacks if they are added after resolution", function() {
var deferred, count1 = 0;
Ember.run(function() {
- deferred = Ember.Object.createWithMixins(Ember.Deferred);
+ deferred = Ember.Object.createWithMixins(Ember.DeferredMixin);
});
stop(); | true |
Other | emberjs | ember.js | 9f8959d4607ba675dec5985412a874aa488d9e58.json | Make promise usage nicer without mixing | packages/ember-runtime/tests/system/deferred_test.js | @@ -0,0 +1,33 @@
+module("Ember.Deferred all-in-one");
+
+asyncTest("Can resolve a promise", function() {
+ var value = { value: true };
+
+ var promise = Ember.Deferred.promise(function(deferred) {
+ setTimeout(function() {
+ Ember.run(function() { deferred.resolve(value); });
+ });
+ });
+
+ promise.then(function(resolveValue) {
+ start();
+ equal(resolveValue, value, "The resolved value should be correct");
+ });
+});
+
+asyncTest("Can reject a promise", function() {
+ var rejected = { rejected: true };
+
+ var promise = Ember.Deferred.promise(function(deferred) {
+ setTimeout(function() {
+ Ember.run(function() { deferred.reject(rejected); });
+ });
+ });
+
+ promise.then(null, function(rejectedValue) {
+ start();
+ equal(rejectedValue, rejected, "The resolved value should be correct");
+ });
+});
+
+ | true |
Other | emberjs | ember.js | 3fbf4b8d29a19d6f9891b48662726b1209a061d3.json | Add redirection and inline documentation | packages/ember-routing/lib/system/route.js | @@ -4,6 +4,19 @@ var get = Ember.get, set = Ember.set,
Ember.Route = Ember.Object.extend({
+ /**
+ Transition into another route. Optionally supply a model for the
+ route in question. The model will be serialized into the URL
+ using the `serialize` hook.
+
+ @param {String} name the name of the route
+ @param {...Object} models the
+ */
+ transitionTo: function() {
+ this.transitioned = true;
+ return this.router.transitionTo.apply(this.router, arguments);
+ },
+
/**
@private
@@ -12,6 +25,11 @@ Ember.Route = Ember.Object.extend({
setup: function(context) {
var container = this.container;
+ this.transitioned = false;
+ this.redirect(context);
+
+ if (this.transitioned) { return; }
+
var templateName = this.templateName,
controller = container.lookup('controller:' + templateName);
@@ -32,20 +50,48 @@ Ember.Route = Ember.Object.extend({
this.renderTemplates(context);
},
+ /**
+ A hook you can implement to optionally redirect to another route.
+
+ If you call `this.transitionTo` from inside of this hook, this route
+ will not be entered in favor of the other hook.
+
+ @param {Object} model the model for this route
+ */
+ redirect: Ember.K,
+
+ /**
+ @private
+
+ The hook called by `router.js` to convert parameters into the context
+ for this handler. The public Ember hook is `model`.
+ */
deserialize: function(params) {
var model = this.model(params);
return this.currentModel = model;
},
- serialize: function(model, params) {
- if (params.length !== 1) { return; }
+ /**
+ A hook you can implement to convert the URL into the model for
+ this route.
- var name = params[0], object = {};
- object[name] = get(model, 'id');
+ ```js
+ App.Route.map(function(match) {
+ match("/posts/:post_id").to("post");
+ });
+ ```
- return object;
- },
+ The model for the `post` route is `App.Post.find(params.post_id)`.
+
+ By default, if your route has a dynamic segment ending in `_id`:
+ * The model class is determined from the segment (`post_id`'s
+ class is `App.Post`)
+ * The find method is called on the model class with the value of
+ the dynamic segment.
+
+ @param {Object} params the parameters extracted from the URL
+ */
model: function(params) {
var match, name, value;
@@ -66,16 +112,113 @@ Ember.Route = Ember.Object.extend({
return modelClass.find(value);
},
- setupControllers: function(controller, context) {
+ /**
+ A hook you can implement to convert the route's model into parameters
+ for the URL.
+
+ ```js
+ App.Route.map(function(match) {
+ match("/posts/:post_id").to("post");
+ });
+
+ App.PostRoute = Ember.Route.extend({
+ model: function(params) {
+ // the server returns `{ id: 12 }`
+ return jQuery.getJSON("/posts/" + params.post_id);
+ },
+
+ serialize: function(model) {
+ // this will make the URL `/posts/12`
+ return { post_id: model.id };
+ }
+ });
+ ```
+
+ The default `serialize` method inserts the model's `id` into the
+ route's dynamic segment (in this case, `:post_id`).
+
+ This method is called when `transitionTo` is called with a context
+ in order to populate the URL.
+
+ @param {Object} model the route's model
+ @param {Array} params an Array of parameter names for the current
+ route (in the example, `['post_id']`.
+ @return {Object} the serialized parameters
+ */
+ serialize: function(model, params) {
+ if (params.length !== 1) { return; }
+
+ var name = params[0], object = {};
+ object[name] = get(model, 'id');
+
+ return object;
+ },
+
+ /**
+ A hook you can use to setup the necessary controllers for the current
+ route.
+
+ This method is called with the controller for the current route and the
+ model supplied by the `model` hook.
+
+ ```js
+ App.Route.map(function(match) {
+ match("/posts/:post_id").to("post");
+ });
+ ```
+
+ For the `post` route, the controller is `App.PostController`.
+
+ By default, the `setupController` hook sets the `content` property of
+ the controller to the `model`.
+
+ If no explicit controller is defined, the route will automatically create
+ an appropriate controller for the model:
+
+ * if the model is an `Ember.Array` (including record arrays from Ember
+ Data), the controller is an `Ember.ArrayController`.
+ * otherwise, the controller is an `Ember.ObjectController`.
+
+ This means that your template will get a proxy for the model as its
+ context, and you can act as though the model itself was the context.
+ */
+ setupControllers: function(controller, model) {
if (controller) {
- controller.set('content', context);
+ controller.set('content', model);
}
},
+ /**
+ Returns the controller for a particular route.
+
+ ```js
+ App.PostRoute = Ember.Route.extend({
+ setupControllers: function(controller, post) {
+ this._super(controller, post);
+ this.controllerFor('posts').set('currentPost', post);
+ }
+ });
+ ```
+
+ By default, the controller for `post` is the shared instance of
+ `App.PostController`.
+
+ @param {String} name the name of the route
+ @return {Ember.Controller}
+ */
controllerFor: function(name) {
return this.container.lookup('controller:' + name);
},
+ /**
+ Returns the current model for a given route.
+
+ This is the object returned by the `model` hook of the route
+ in question.
+
+ @param {String} name the name of the route
+ @return {Object} the model object
+ */
modelFor: function(name) {
return this.container.lookup('route:' + name).currentModel;
}, | true |
Other | emberjs | ember.js | 3fbf4b8d29a19d6f9891b48662726b1209a061d3.json | Add redirection and inline documentation | packages/ember-routing/tests/integration/basic_test.js | @@ -644,4 +644,32 @@ test("It is possible to get the model from a parent route", function() {
});
});
+test("A redirection hook is provided", function() {
+ Router.map(function(match) {
+ match("/").to("choose");
+ match("/home").to("home");
+ });
+
+ var chooseFollowed = 0, destination;
+
+ App.ChooseRoute = Ember.Route.extend({
+ redirect: function() {
+ if (destination) {
+ this.transitionTo(destination);
+ }
+ },
+
+ setupControllers: function() {
+ chooseFollowed++;
+ }
+ });
+
+ destination = 'home';
+
+ bootApplication();
+
+ equal(chooseFollowed, 0, "The choose route wasn't entered since a transition occurred");
+ equal(Ember.$("h3:contains(Hours)", "#qunit-fixture").length, 1, "The home template was rendered");
+});
+
// TODO: Parent context change | true |
Other | emberjs | ember.js | e4aefe6366e335e126c03c803c094f4e83a7d32b.json | Add documentation to `render` | packages/ember-routing/lib/system/route.js | @@ -84,6 +84,56 @@ Ember.Route = Ember.Object.extend({
this.render();
},
+ /**
+ Renders a template into an outlet.
+
+ This method has a number of defaults, based on the name of the
+ route specified in the router.
+
+ For example:
+
+ ```js
+ App.Router.map(function(match) {
+ match("/").to("index");
+ match("/posts/:post_id").to("post");
+ });
+
+ App.PostRoute = App.Route.extend({
+ renderTemplates: function() {
+ this.render();
+ }
+ });
+ ```
+
+ The name of the `PostRoute`, as defined by the router, is `post`.
+
+ By default, render will:
+
+ * render the `post` template
+ * with the `post` view (`PostView`) for event handling, if one exists
+ * and the `post` controller (`PostController`), if one exists
+ * into the `main` outlet of the `application` template
+
+ You can override this behavior:
+
+ ```js
+ App.PostRoute = App.Route.extend({
+ renderTemplates: function() {
+ this.render('myPost', { // the template to render
+ into: 'index', // the template to render into
+ outlet: 'detail', // the name of the outlet in that template
+ controller: 'blogPost' // the controller to use for the template
+ });
+ }
+ });
+ ```
+
+ Remember that the controller's `content` will be the route's model. In
+ this case, the default model will be `App.Post.find(params.post_id)`.
+
+ @param {String} name the name of the template to render
+ @param {Object} options the options
+ */
render: function(name, options) {
if (typeof name === 'object' && !options) {
options = name; | false |
Other | emberjs | ember.js | c87ad9fc13f7883e7b898c9fb9b1630cb2fc9bf1.json | Improve linkTo and write more tests | packages/ember-routing/lib/handlebars_ext.js | @@ -98,55 +98,78 @@ Ember.onLoad('Ember.Handlebars', function(Handlebars) {
}
});
-});
+ function args(linkView, route) {
+ var ret = [ route || linkView.namedRoute ],
+ params = linkView.parameters,
+ contexts = params.contexts,
+ roots = params.roots,
+ data = params.data;
+
+ for (var i=0, l=contexts.length; i<l; i++) {
+ ret.push( Ember.Handlebars.get(roots[i], contexts[i], { data: data }) );
+ }
+
+ return ret;
+ }
-function args(linkView) {
- var ret = [ linkView.namedRoute ],
- params = linkView.parameters,
- contexts = params.contexts,
- roots = params.roots,
- data = params.data;
+ function simpleClick(event) {
+ var modifier = event.shiftKey || event.metaKey || event.altKey || event.ctrlKey,
+ secondaryClick = event.which > 1; // IE9 may return undefined
- for (var i=0, l=contexts.length; i<l; i++) {
- ret.push( Ember.Handlebars.get(roots[i], contexts[i], { data: data }) );
+ return !modifier && !secondaryClick;
}
- return ret;
-}
+ var LinkView = Ember.View.extend({
+ tagName: 'a',
+ namedRoute: null,
+ currentWhen: null,
+ activeClass: 'active',
+ attributeBindings: 'href',
+ classNameBindings: 'active',
-var LinkView = Ember.View.extend({
- tagName: 'a',
- attributeBindings: 'href',
+ active: Ember.computed(function() {
+ var router = this.get('router'),
+ isActive = router.isActive.apply(router, args(this, this.currentWhen));
- click: function() {
- this.router.transitionTo.apply(this.router, args(this));
- return false;
- },
+ if (isActive) { return get(this, 'activeClass'); }
+ }).property('namedRoute', 'router.url'),
- href: Ember.computed(function() {
- // TODO: Fix this in route-recognizer
- return this.router.generate.apply(this.router, args(this)) || "/";
- })
-});
+ router: Ember.computed(function() {
+ return this.get('controller').container.lookup('router:main');
+ }),
+
+ click: function(event) {
+ if (!simpleClick(event)) { return true; }
-LinkView.toString = function() { return "LinkView"; };
+ var router = this.get('router');
+ router.transitionTo.apply(router, args(this));
+ return false;
+ },
+
+ href: Ember.computed(function() {
+ var router = this.get('router');
+ return router.generate.apply(router, args(this));
+ })
+ });
-Ember.Handlebars.registerHelper('linkTo', function(name) {
- var options = [].slice.call(arguments, -1)[0];
- var contexts = [].slice.call(arguments, 1, -1);
+ LinkView.toString = function() { return "LinkView"; };
- var hash = options.hash;
+ Ember.Handlebars.registerHelper('linkTo', function(name) {
+ var options = [].slice.call(arguments, -1)[0];
+ var contexts = [].slice.call(arguments, 1, -1);
- var controller = options.data.keywords.controller;
- Ember.assert("You cannot use the {{linkTo}} helper because your current template does not have a controller", controller.target);
+ var hash = options.hash;
- hash.namedRoute = name;
- hash.router = controller.target;
- hash.parameters = {
- data: options.data,
- contexts: contexts,
- roots: options.contexts
- };
+ hash.namedRoute = name;
+ hash.currentWhen = hash.currentWhen || name;
+
+ hash.parameters = {
+ data: options.data,
+ contexts: contexts,
+ roots: options.contexts
+ };
+
+ return Ember.Handlebars.helpers.view.call(this, LinkView, options);
+ });
- return Ember.Handlebars.helpers.view.call(this, LinkView, options);
}); | true |
Other | emberjs | ember.js | c87ad9fc13f7883e7b898c9fb9b1630cb2fc9bf1.json | Improve linkTo and write more tests | packages/ember-routing/tests/helpers/link_to_test.js | @@ -21,8 +21,8 @@ module("The {{linkTo}} helper", {
container = Ember.Application.buildContainer(App);
Ember.TEMPLATES.app = Ember.Handlebars.compile("{{outlet}}");
- Ember.TEMPLATES.home = Ember.Handlebars.compile("<h3>Home</h3>{{#linkTo about id='about-link'}}About{{/linkTo}}");
- Ember.TEMPLATES.about = Ember.Handlebars.compile("<h3>About</h3>{{#linkTo home id='home-link'}}Home{{/linkTo}}");
+ Ember.TEMPLATES.home = Ember.Handlebars.compile("<h3>Home</h3>{{#linkTo about id='about-link'}}About{{/linkTo}}{{#linkTo home id='self-link'}}Self{{/linkTo}}");
+ Ember.TEMPLATES.about = Ember.Handlebars.compile("<h3>About</h3>{{#linkTo home id='home-link'}}Home{{/linkTo}}{{#linkTo about id='self-link'}}Self{{/linkTo}}");
Ember.TEMPLATES.item = Ember.Handlebars.compile("<h3>Item</h3><p>{{name}}</p>{{#linkTo home id='home-link'}}Home{{/linkTo}}");
Router = Ember.Router.extend({
@@ -59,12 +59,56 @@ test("The {{linkTo}} helper moves into the named route", function() {
});
equal(Ember.$('h3:contains(Home)', '#qunit-fixture').length, 1, "The home template was rendered");
+ equal(Ember.$('#self-link.active', '#qunit-fixture').length, 1, "The self-link was rendered with active class");
+ equal(Ember.$('#about-link:not(.active)', '#qunit-fixture').length, 1, "The other link was rendered without active class");
Ember.run(function() {
- Ember.$('a', '#qunit-fixture').click();
+ Ember.$('#about-link', '#qunit-fixture').click();
});
equal(Ember.$('h3:contains(About)', '#qunit-fixture').length, 1, "The about template was rendered");
+ equal(Ember.$('#self-link.active', '#qunit-fixture').length, 1, "The self-link was rendered with active class");
+ equal(Ember.$('#home-link:not(.active)', '#qunit-fixture').length, 1, "The other link was rendered without active class");
+});
+
+test("The {{linkTo}} helper supports a custom activeClass", function() {
+ Ember.TEMPLATES.home = Ember.Handlebars.compile("<h3>Home</h3>{{#linkTo about id='about-link'}}About{{/linkTo}}{{#linkTo home id='self-link' activeClass='zomg-active'}}Self{{/linkTo}}");
+
+ Router.map(function(match) {
+ match("/").to("home");
+ match("/about").to("about");
+ });
+
+ bootApplication();
+
+ Ember.run(function() {
+ router.handleURL("/");
+ });
+
+ equal(Ember.$('h3:contains(Home)', '#qunit-fixture').length, 1, "The home template was rendered");
+ equal(Ember.$('#self-link.zomg-active', '#qunit-fixture').length, 1, "The self-link was rendered with active class");
+ equal(Ember.$('#about-link:not(.active)', '#qunit-fixture').length, 1, "The other link was rendered without active class");
+});
+
+test("The {{linkTo}} helper supports custom, nested, currentWhen", function() {
+ Router.map(function(match) {
+ match("/").to("home", function(match) {
+ match("/").to("index");
+ match("/about").to("about");
+ });
+ match("/item").to("item");
+ });
+
+ Ember.TEMPLATES.home = Ember.Handlebars.compile("<h3>Home</h3>{{outlet}}");
+ Ember.TEMPLATES.about = Ember.Handlebars.compile("{{#linkTo item id='other-link' currentWhen='home'}}ITEM{{/linkTo}}");
+
+ bootApplication();
+
+ Ember.run(function() {
+ router.handleURL("/about");
+ });
+
+ equal(Ember.$('#other-link.active', '#qunit-fixture').length, 1, "The link is active since currentWhen is a parent route");
});
test("The {{linkTo}} helper moves into the named route with context", function() { | true |
Other | emberjs | ember.js | c0207ba0a0948f70ed65f5e3095ec7ea40463259.json | Add capitalize function to Ember.String
Conflicts:
packages/ember-runtime/lib/ext/string.js | packages/ember-runtime/lib/ext/string.js | @@ -15,6 +15,7 @@ var fmt = Ember.String.fmt,
decamelize = Ember.String.decamelize,
dasherize = Ember.String.dasherize,
underscore = Ember.String.underscore,
+ capitalize = Ember.String.capitalize,
classify = Ember.String.classify;
if (Ember.EXTEND_PROTOTYPES === true || Ember.EXTEND_PROTOTYPES.String) {
@@ -98,5 +99,16 @@ if (Ember.EXTEND_PROTOTYPES === true || Ember.EXTEND_PROTOTYPES.String) {
String.prototype.classify = function() {
return classify(this);
};
+
+ /**
+ See {{#crossLink "Ember.String/capitalize"}}{{/crossLink}}
+
+ @method capitalize
+ @for String
+ */
+ String.prototype.capitalize = function() {
+ return capitalize(this);
+ };
+
}
| true |
Other | emberjs | ember.js | c0207ba0a0948f70ed65f5e3095ec7ea40463259.json | Add capitalize function to Ember.String
Conflicts:
packages/ember-runtime/lib/ext/string.js | packages/ember-runtime/lib/system/string.js | @@ -214,5 +214,22 @@ Ember.String = {
underscore: function(str) {
return str.replace(STRING_UNDERSCORE_REGEXP_1, '$1_$2').
replace(STRING_UNDERSCORE_REGEXP_2, '_').toLowerCase();
+ },
+
+ /**
+ Returns the Capitalized form of a string
+
+ 'innerHTML'.capitalize() => 'InnerHTML'
+ 'action_name'.capitalize() => 'Action_name'
+ 'css-class-name'.capitalize() => 'Css-class-name'
+ 'my favorite items'.capitalize() => 'My favorite items'
+
+ @param {String} str
+
+ @returns {String}
+ */
+ capitalize: function(str) {
+ return str.charAt(0).toUpperCase() + str.substr(1);
}
+
}; | true |
Other | emberjs | ember.js | c0207ba0a0948f70ed65f5e3095ec7ea40463259.json | Add capitalize function to Ember.String
Conflicts:
packages/ember-runtime/lib/ext/string.js | packages/ember-runtime/tests/system/string/capitalize.js | @@ -0,0 +1,44 @@
+// ==========================================================================
+// Project: Ember Runtime
+// Copyright: ©2006-2011 Strobe Inc. and contributors.
+// ©2008-2011 Apple Inc. All rights reserved.
+// License: Licensed under MIT license (see license.js)
+// ==========================================================================
+
+module('Ember.String.capitalize');
+
+test("capitalize normal string", function() {
+ deepEqual(Ember.String.capitalize('my favorite items'), 'My favorite items');
+ if (Ember.EXTEND_PROTOTYPES) {
+ deepEqual('my favorite items'.capitalize(), 'My favorite items');
+ }
+});
+
+test("capitalize dasherized string", function() {
+ deepEqual(Ember.String.capitalize('css-class-name'), 'Css-class-name');
+ if (Ember.EXTEND_PROTOTYPES) {
+ deepEqual('css-class-name'.capitalize(), 'Css-class-name');
+ }
+});
+
+test("capitalize underscored string", function() {
+ deepEqual(Ember.String.capitalize('action_name'), 'Action_name');
+ if (Ember.EXTEND_PROTOTYPES) {
+ deepEqual('action_name'.capitalize(), 'Action_name');
+ }
+});
+
+test("capitalize camelcased string", function() {
+ deepEqual(Ember.String.capitalize('innerHTML'), 'InnerHTML');
+ if (Ember.EXTEND_PROTOTYPES) {
+ deepEqual('innerHTML'.capitalize(), 'InnerHTML');
+ }
+});
+
+test("does nothing with capitalized string", function() {
+ deepEqual(Ember.String.capitalize('Capitalized string'), 'Capitalized string');
+ if (Ember.EXTEND_PROTOTYPES) {
+ deepEqual('Capitalized string'.capitalize(), 'Capitalized string');
+ }
+});
+ | true |
Other | emberjs | ember.js | a511b094fc720f5ba4c612c3dff610f3dc39d231.json | Add custom names to Ember.Namespace | packages/ember-runtime/lib/system/namespace.js | @@ -5,7 +5,7 @@ require('ember-runtime/system/object');
@submodule ember-runtime
*/
-var indexOf = Ember.ArrayPolyfills.indexOf;
+var get = Ember.get, indexOf = Ember.ArrayPolyfills.indexOf;
/**
A Namespace is an object usually used to contain other objects or methods
@@ -33,6 +33,9 @@ Ember.Namespace = Ember.Object.extend({
},
toString: function() {
+ var name = get(this, 'name');
+ if (name) { return name; }
+
Ember.identifyNamespaces();
return this[Ember.GUID_KEY+'_name'];
}, | true |
Other | emberjs | ember.js | a511b094fc720f5ba4c612c3dff610f3dc39d231.json | Add custom names to Ember.Namespace | packages/ember-runtime/tests/system/namespace/base_test.js | @@ -79,3 +79,19 @@ test("Lowercase namespaces should be deprecated", function() {
// Ignore backtrace
equal(loggerWarning.split("\n")[0], "DEPRECATION: Namespaces should not begin with lowercase.");
});
+
+test("A namespace can be assigned a custom name", function() {
+ var nsA = Ember.Namespace.create({
+ name: "NamespaceA"
+ });
+
+ var nsB = lookup.NamespaceB = Ember.Namespace.create({
+ name: "CustomNamespaceB"
+ });
+
+ nsA.Foo = Ember.Object.extend();
+ nsB.Foo = Ember.Object.extend();
+
+ equal(nsA.Foo.toString(), "NamespaceA.Foo", "The namespace's name is used when the namespace is not in the lookup object");
+ equal(nsB.Foo.toString(), "CustomNamespaceB.Foo", "The namespace's name is used when the namespace is in the lookup object");
+}); | true |
Other | emberjs | ember.js | 1948a604bf86200a5ab9187d93be669b370b5d5a.json | Reorganize mixins and mergeMixins | packages/ember-metal/lib/mixin.js | @@ -56,103 +56,136 @@ function isMethod(obj) {
obj !== Boolean && obj !== Object && obj !== Number && obj !== Array && obj !== Date && obj !== String;
}
-function mergeMixins(mixins, m, descs, values, base) {
- var len = mixins.length, idx, mixin, guid, props, value, key, ovalue, concats, meta;
+function cloneDescriptor(desc) {
+ var newDesc = new Ember.ComputedProperty();
+ newDesc._cacheable = desc._cacheable;
+ newDesc._dependentKeys = desc._dependentKeys;
+ newDesc.func = desc.func;
- function removeKeys(keyName) {
- delete descs[keyName];
- delete values[keyName];
+ return newDesc;
+}
+
+var CONTINUE = {};
+
+function mixinProperties(mixinsMeta, mixin) {
+ var guid;
+
+ if (mixin instanceof Mixin) {
+ guid = guidFor(mixin);
+ if (mixinsMeta[guid]) { return CONTINUE; }
+ mixinsMeta[guid] = mixin;
+ return mixin.properties;
+ } else {
+ return mixin; // apply anonymous mixin properties
+ }
+}
+
+function concatenatedProperties(props, values, base) {
+ var concats;
+
+ // reset before adding each new mixin to pickup concats from previous
+ concats = values.concatenatedProperties || base.concatenatedProperties;
+ if (props.concatenatedProperties) {
+ concats = concats ? concats.concat(props.concatenatedProperties) : props.concatenatedProperties;
}
- function cloneDescriptor(desc) {
- var newDesc = new Ember.ComputedProperty();
- newDesc._cacheable = desc._cacheable;
- newDesc._dependentKeys = desc._dependentKeys;
- newDesc.func = desc.func;
+ return concats;
+}
- return newDesc;
+function giveDescriptorSuper(meta, key, value, values, descs) {
+ var ovalue = values[key] === undefined && descs[key];
+ if (!ovalue) { ovalue = meta.descs[key]; }
+ if (ovalue && ovalue.func) {
+ // Since multiple mixins may inherit from the
+ // same parent, we need to clone the computed
+ // property so that other mixins do not receive
+ // the wrapped version.
+ value = cloneDescriptor(value);
+ value.func = Ember.wrap(value.func, ovalue.func);
}
- for(idx=0; idx < len; idx++) {
- mixin = mixins[idx];
- Ember.assert('Expected hash or Mixin instance, got ' + Object.prototype.toString.call(mixin), typeof mixin === 'object' && mixin !== null && Object.prototype.toString.call(mixin) !== '[object Array]');
+ return value;
+}
- if (mixin instanceof Mixin) {
- guid = guidFor(mixin);
- if (m[guid]) { continue; }
- m[guid] = mixin;
- props = mixin.properties;
+function giveMethodSuper(obj, key, value, values, descs) {
+ var ovalue = descs[key] === undefined && values[key];
+ if (!ovalue) { ovalue = obj[key]; }
+ if ('function' !== typeof ovalue) { ovalue = null; }
+ if (ovalue) {
+ var o = value.__ember_observes__, ob = value.__ember_observesBefore__;
+ value = Ember.wrap(value, ovalue);
+ value.__ember_observes__ = o;
+ value.__ember_observesBefore__ = ob;
+ }
+
+ return value;
+}
+
+function applyConcatenatedProperties(obj, key, value, values) {
+ var baseValue = values[key] || obj[key];
+
+ if (baseValue) {
+ if ('function' === typeof baseValue.concat) {
+ return baseValue.concat(value);
} else {
- props = mixin; // apply anonymous mixin properties
+ return Ember.makeArray(baseValue).concat(value);
+ }
+ } else {
+ return Ember.makeArray(value);
+ }
+}
+
+function addNormalizedProperty(base, key, value, meta, descs, values, concats) {
+ if (value instanceof Ember.Descriptor) {
+ if (value === REQUIRED && descs[key]) { return CONTINUE; }
+
+ // Wrap descriptor function to implement
+ // _super() if needed
+ if (value.func) {
+ value = giveDescriptorSuper(meta, key, value, values, descs);
+ }
+
+ descs[key] = value;
+ values[key] = undefined;
+ } else {
+ // impl super if needed...
+ if (isMethod(value)) {
+ value = giveMethodSuper(base, key, value, values, descs);
+ } else if ((concats && a_indexOf.call(concats, key) >= 0) || key === 'concatenatedProperties') {
+ value = applyConcatenatedProperties(base, key, value, values);
}
+ descs[key] = undefined;
+ values[key] = value;
+ }
+}
+
+function mergeMixins(mixins, m, descs, values, base) {
+ var mixin, props, key, concats, meta;
+
+ function removeKeys(keyName) {
+ delete descs[keyName];
+ delete values[keyName];
+ }
+
+ for(var i=0, l=mixins.length; i<l; i++) {
+ mixin = mixins[i];
+ Ember.assert('Expected hash or Mixin instance, got ' + Object.prototype.toString.call(mixin), typeof mixin === 'object' && mixin !== null && Object.prototype.toString.call(mixin) !== '[object Array]');
+
+ props = mixinProperties(m, mixin);
+ if (props === CONTINUE) { continue; }
+
if (props) {
meta = Ember.meta(base);
-
- // reset before adding each new mixin to pickup concats from previous
- concats = values.concatenatedProperties || base.concatenatedProperties;
- if (props.concatenatedProperties) {
- concats = concats ? concats.concat(props.concatenatedProperties) : props.concatenatedProperties;
- }
+ concats = concatenatedProperties(props, values, base);
for (key in props) {
if (!props.hasOwnProperty(key)) { continue; }
- value = props[key];
- if (value instanceof Ember.Descriptor) {
- if (value === REQUIRED && descs[key]) { continue; }
-
- // Wrap descriptor function to implement
- // _super() if needed
- if (value.func) {
- ovalue = values[key] === undefined && descs[key];
- if (!ovalue) { ovalue = meta.descs[key]; }
- if (ovalue && ovalue.func) {
- // Since multiple mixins may inherit from the
- // same parent, we need to clone the computed
- // property so that other mixins do not receive
- // the wrapped version.
- value = cloneDescriptor(value);
- value.func = Ember.wrap(value.func, ovalue.func);
- }
- }
-
- descs[key] = value;
- values[key] = undefined;
- } else {
- // impl super if needed...
- if (isMethod(value)) {
- ovalue = descs[key] === undefined && values[key];
- if (!ovalue) { ovalue = base[key]; }
- if ('function' !== typeof ovalue) { ovalue = null; }
- if (ovalue) {
- var o = value.__ember_observes__, ob = value.__ember_observesBefore__;
- value = Ember.wrap(value, ovalue);
- value.__ember_observes__ = o;
- value.__ember_observesBefore__ = ob;
- }
- } else if ((concats && a_indexOf.call(concats, key) >= 0) || key === 'concatenatedProperties') {
- var baseValue = values[key] || base[key];
- if (baseValue) {
- if ('function' === typeof baseValue.concat) {
- value = baseValue.concat(value);
- } else {
- value = Ember.makeArray(baseValue).concat(value);
- }
- } else {
- value = Ember.makeArray(value);
- }
- }
-
- descs[key] = undefined;
- values[key] = value;
- }
+ addNormalizedProperty(base, key, props[key], meta, descs, values, concats);
}
// manually copy toString() because some JS engines do not enumerate it
- if (props.hasOwnProperty('toString')) {
- base.toString = props.toString;
- }
-
+ if (props.hasOwnProperty('toString')) { base.toString = props.toString; }
} else if (mixin.mixins) {
mergeMixins(mixin.mixins, m, descs, values, base);
if (mixin._without) { a_forEach.call(mixin._without, removeKeys); }
@@ -212,9 +245,47 @@ function finishPartial(obj, m) {
return obj;
}
+function followAlias(obj, desc, m, descs, values) {
+ var altKey = desc.methodName, value;
+ if (descs[altKey] || values[altKey]) {
+ value = values[altKey];
+ desc = descs[altKey];
+ } else if (m.descs[altKey]) {
+ desc = m.descs[altKey];
+ value = undefined;
+ } else {
+ desc = undefined;
+ value = obj[altKey];
+ }
+
+ return { desc: desc, value: value };
+}
+
+function updateObservers(obj, key, observer, observerKey, method) {
+ if ('function' !== typeof observer) { return; }
+
+ var paths = observer[observerKey];
+
+ if (paths) {
+ for (var i=0, l=paths.length; i<l; i++) {
+ Ember[method](obj, paths[i], null, key);
+ }
+ }
+}
+
+function replaceObservers(obj, key, observer) {
+ var prevObserver = obj[key];
+
+ updateObservers(obj, key, prevObserver, '__ember_observesBefore__', 'removeBeforeObserver');
+ updateObservers(obj, key, prevObserver, '__ember_observes__', 'removeObserver');
+
+ updateObservers(obj, key, observer, '__ember_observesBefore__', 'addBeforeObserver');
+ updateObservers(obj, key, observer, '__ember_observes__', 'addObserver');
+}
+
function applyMixin(obj, mixins, partial) {
- var descs = {}, values = {}, m = Ember.meta(obj), req = m.required,
- key, value, desc, prevValue, paths, len, idx;
+ var descs = {}, values = {}, m = Ember.meta(obj),
+ key, value, desc;
// Go through all mixins and hashes passed in, and:
//
@@ -225,94 +296,30 @@ function applyMixin(obj, mixins, partial) {
mergeMixins(mixins, mixinsMeta(obj), descs, values, obj);
for(key in values) {
- if (key === 'contructor') { continue; }
- if (!values.hasOwnProperty(key)) { continue; }
+ if (key === 'contructor' || !values.hasOwnProperty(key)) { continue; }
desc = descs[key];
value = values[key];
- if (desc === REQUIRED) {
- if (!(key in obj)) {
- Ember.assert('Required property not defined: '+key, !!partial);
-
- // for partial applies add to hash of required keys
- req = writableReq(obj);
- req.__ember_count__++;
- req[key] = true;
- }
- } else {
- while (desc && desc instanceof Alias) {
- var altKey = desc.methodName;
- if (descs[altKey] || values[altKey]) {
- value = values[altKey];
- desc = descs[altKey];
- } else if (m.descs[altKey]) {
- desc = m.descs[altKey];
- value = undefined;
- } else {
- desc = undefined;
- value = obj[altKey];
- }
- }
+ if (desc === REQUIRED) { continue; }
- if (desc === undefined && value === undefined) { continue; }
-
- prevValue = obj[key];
-
- if ('function' === typeof prevValue) {
- if ((paths = prevValue.__ember_observesBefore__)) {
- len = paths.length;
- for (idx=0; idx < len; idx++) {
- Ember.removeBeforeObserver(obj, paths[idx], null, key);
- }
- } else if ((paths = prevValue.__ember_observes__)) {
- len = paths.length;
- for (idx=0; idx < len; idx++) {
- Ember.removeObserver(obj, paths[idx], null, key);
- }
- }
- }
+ while (desc && desc instanceof Alias) {
+ var followed = followAlias(obj, desc, m, descs, values);
+ desc = followed.desc;
+ value = followed.value;
+ }
- detectBinding(obj, key, value, m);
-
- defineProperty(obj, key, desc, value, m);
-
- if ('function' === typeof value) {
- if (paths = value.__ember_observesBefore__) {
- len = paths.length;
- for (idx=0; idx < len; idx++) {
- Ember.addBeforeObserver(obj, paths[idx], null, key);
- }
- } else if (paths = value.__ember_observes__) {
- len = paths.length;
- for (idx=0; idx < len; idx++) {
- Ember.addObserver(obj, paths[idx], null, key);
- }
- }
- }
+ if (desc === undefined && value === undefined) { continue; }
- if (req && req[key]) {
- req = writableReq(obj);
- req.__ember_count__--;
- req[key] = false;
- }
- }
+ replaceObservers(obj, key, value);
+ detectBinding(obj, key, value, m);
+ defineProperty(obj, key, desc, value, m);
}
if (!partial) { // don't apply to prototype
finishPartial(obj, m);
}
- // Make sure no required attrs remain
- if (!partial && req && req.__ember_count__>0) {
- var keys = [];
- for (key in req) {
- if (META_SKIP[key]) { continue; }
- keys.push(key);
- }
- // TODO: Remove surrounding if clause from production build
- Ember.assert('Required properties not defined: '+keys.join(','));
- }
return obj;
}
| true |
Other | emberjs | ember.js | 1948a604bf86200a5ab9187d93be669b370b5d5a.json | Reorganize mixins and mergeMixins | packages/ember-metal/tests/mixin/required_test.js | @@ -21,23 +21,6 @@ module('Module.required', {
}
});
-test('applying a mixin with unmet requirement', function() {
- raises(function() {
- PartialMixin.apply(obj);
- }, Error, 'should raise error for unmet requirement');
-});
-
-test('applying a mixin with unmet requirement using applyPartial', function() {
- PartialMixin.applyPartial(obj);
- equal(obj.foo, null, 'obj.foo has required');
-
- // applying regularly to object should throw
- raises(function() {
- Ember.Mixin.create({ bar: 'BAR' }).apply(obj);
- }, Error, 'should raise error for unmet requirement');
-
-});
-
test('applying a mixin to meet requirement', function() {
FinalMixin.apply(obj);
PartialMixin.apply(obj); | true |
Other | emberjs | ember.js | f0b653e37b60e62cc16a69e28575af7387c386e3.json | Fix Select test to append to right place | packages/ember-handlebars/tests/controls/select_test.js | @@ -26,7 +26,7 @@ function setAndFlush(view, key, value) {
function append() {
Ember.run(function() {
- select.appendTo('body');
+ select.appendTo('#qunit-fixture');
});
}
| false |
Other | emberjs | ember.js | 041cb831cf3ed938ae765ab3b3a6484d25f0d26e.json | Fix precompilation test in IE | packages/ember-handlebars/tests/handlebars_test.js | @@ -1767,7 +1767,7 @@ test("should be able to use unbound helper in #each helper (with objects)", func
test("should work with precompiled templates", function() {
var templateString = Ember.Handlebars.precompile("{{view.value}}"),
- compiledTemplate = Ember.Handlebars.template(eval('('+templateString+')'));
+ compiledTemplate = Ember.Handlebars.template(eval(templateString));
view = Ember.View.create({
value: "rendered",
template: compiledTemplate | false |
Other | emberjs | ember.js | e4b1b073b12f5baf2800cffab47d1f828988d58d.json | Fix prompt value in IE8 | packages/ember-handlebars/lib/controls/select.js | @@ -264,7 +264,7 @@ Ember.Select = Ember.View.extend(
tagName: 'select',
classNames: ['ember-select'],
- defaultTemplate: Ember.Handlebars.compile('{{#if view.prompt}}<option value>{{view.prompt}}</option>{{/if}}{{#each view.content}}{{view Ember.SelectOption contentBinding="this"}}{{/each}}'),
+ defaultTemplate: Ember.Handlebars.compile('{{#if view.prompt}}<option value="">{{view.prompt}}</option>{{/if}}{{#each view.content}}{{view Ember.SelectOption contentBinding="this"}}{{/each}}'),
attributeBindings: ['multiple', 'disabled', 'tabindex'],
/** | false |
Other | emberjs | ember.js | 0bc406cc0096f58b6f428afce4fdfb200c643fe5.json | Fix Select tests on IE8
Previously, the RenderBuffer was trying to set innerHTML on the select
tag which isn't supported by IE8. This add an assert for that case and
changes tests to avoid this. | packages/ember-handlebars/tests/controls/select_test.js | @@ -1,18 +1,21 @@
var map = Ember.EnumerableUtils.map;
-var dispatcher, select;
+var dispatcher, wrapper, select;
module("Ember.Select", {
setup: function() {
dispatcher = Ember.EventDispatcher.create();
dispatcher.setup();
+ wrapper = Ember.ContainerView.create();
select = Ember.Select.create();
+ wrapper.get('childViews').pushObject(select);
},
teardown: function() {
Ember.run(function() {
dispatcher.destroy();
select.destroy();
+ wrapper.destroy();
});
}
});
@@ -25,7 +28,7 @@ function setAndFlush(view, key, value) {
function append() {
Ember.run(function() {
- select.appendTo('#qunit-fixture');
+ wrapper.appendTo('#qunit-fixture');
});
}
| true |
Other | emberjs | ember.js | 0bc406cc0096f58b6f428afce4fdfb200c643fe5.json | Fix Select tests on IE8
Previously, the RenderBuffer was trying to set innerHTML on the select
tag which isn't supported by IE8. This add an assert for that case and
changes tests to avoid this. | packages/ember-views/lib/system/render_buffer.js | @@ -81,6 +81,27 @@ var setInnerHTML = function(element, html) {
/*** END METAMORPH HELPERS */
+var allowedTags = {};
+var allowedAsRoot = function(tagName) {
+ if (allowedTags[tagName] !== undefined) {
+ return allowedTags[tagName];
+ }
+
+ var allowed = true;
+
+ // IE 8 and earlier don't allow us to do innerHTML on select
+ if (tagName.toLowerCase() === 'select') {
+ var el = document.createElement('select');
+ setInnerHTML(el, '<option value="test">Test</option>');
+ allowed = el.options.length === 1;
+ }
+
+ allowedTags[tagName] = allowed;
+
+ return allowed;
+};
+
+
var ClassSet = function() {
this.seen = {};
@@ -391,6 +412,8 @@ Ember._RenderBuffer.prototype =
style = this.elementStyle,
styleBuffer = '', prop;
+ Ember.assert("Can't create a RenderBuffer for "+tagName+" in this browser.", allowedAsRoot(tagName));
+
if (id) {
$element.attr('id', id);
this.elementId = null; | true |
Other | emberjs | ember.js | 7867be4471a3111e828b35dade7c8b2d036e5a78.json | Update router.js (allow redirection) | packages/ember-routing/lib/vendor/router.js | @@ -82,9 +82,10 @@ define("router",
var params = output.params, toSetup = output.toSetup;
- setupContexts(this, toSetup);
var url = this.recognizer.generate(name, params);
this.updateURL(url);
+
+ setupContexts(this, toSetup);
},
/** | false |
Other | emberjs | ember.js | 3c489d6f3263895c672692b9b3b171fea7191924.json | Fix bug with metamorph views and outlets | packages/ember-routing/lib/handlebars_ext.js | @@ -54,7 +54,7 @@ Ember.onLoad('Ember.Handlebars', function(Handlebars) {
property = 'main';
}
- options.hash.currentViewBinding = "view._outlets." + property;
+ options.hash.currentViewBinding = "_view._outlets." + property;
return Handlebars.helpers.view.call(this, Handlebars.OutletView, options);
}); | true |
Other | emberjs | ember.js | 3c489d6f3263895c672692b9b3b171fea7191924.json | Fix bug with metamorph views and outlets | packages/ember-routing/tests/helpers/outlet_test.js | @@ -70,3 +70,34 @@ test("outlet should support an optional name", function() {
equal(view.$().text(), 'HIBYE');
});
+
+test("Outlets bind to the current view, not the current concrete view", function() {
+ var parentTemplate = "<h1>HI</h1>{{outlet}}";
+ var middleTemplate = "<h2>MIDDLE</h2>{{outlet}}";
+ var bottomTemplate = "<h3>BOTTOM</h3>";
+
+ view = Ember.View.create({
+ template: compile(parentTemplate)
+ });
+
+ var middleView = Ember._MetamorphView.create({
+ template: compile(middleTemplate)
+ });
+
+ var bottomView = Ember._MetamorphView.create({
+ template: compile(bottomTemplate)
+ });
+
+ appendView(view);
+
+ Ember.run(function() {
+ view.connectOutlet('main', middleView);
+ });
+
+ Ember.run(function() {
+ middleView.connectOutlet('main', bottomView);
+ });
+
+ var output = Ember.$('#qunit-fixture h1 ~ h2 ~ h3').text();
+ equal(output, "BOTTOM", "all templates were rendered");
+}); | true |
Other | emberjs | ember.js | 3c489d6f3263895c672692b9b3b171fea7191924.json | Fix bug with metamorph views and outlets | packages/ember-views/lib/views/view.js | @@ -1115,6 +1115,7 @@ Ember.View = Ember.CoreView.extend(
var keywords = templateData ? Ember.copy(templateData.keywords) : {};
set(keywords, 'view', get(this, 'concreteView'));
+ set(keywords, '_view', this);
set(keywords, 'controller', get(this, 'controller'));
return keywords; | true |
Other | emberjs | ember.js | cc75d4e4e493d6322000d86f7939500fb46e7ec4.json | Fix extra closing tag in RenderBuffer | packages/ember-views/lib/system/render_buffer.js | @@ -306,7 +306,8 @@ Ember._RenderBuffer.prototype =
},
generateElement: function() {
- var element = document.createElement(this.currentTagName()),
+ var tagName = this.tagNames.pop(), // pop since we don't need to close
+ element = document.createElement(tagName),
$element = Ember.$(element),
id = this.elementId,
classes = this.classes, | false |
Other | emberjs | ember.js | e4a867039190a4b59bee434f8776731ae7dbc484.json | Fix an instance of Array#indexOf in IE8 | packages/ember-runtime/lib/system/core_object.js | @@ -25,7 +25,8 @@ var set = Ember.set, get = Ember.get,
finishPartial = Mixin.finishPartial,
reopen = Mixin.prototype.reopen,
classToString = Mixin.prototype.toString,
- MANDATORY_SETTER = Ember.ENV.MANDATORY_SETTER;
+ MANDATORY_SETTER = Ember.ENV.MANDATORY_SETTER,
+ indexOf = Ember.EnumerableUtils.indexOf;
var undefinedDescriptor = {
configurable: true,
@@ -87,7 +88,7 @@ function makeCtor() {
Ember.assert("Ember.Object.create no longer supports defining computed properties.", !(value instanceof Ember.ComputedProperty));
Ember.assert("Ember.Object.create no longer supports defining methods that call _super.", !(typeof value === 'function' && value.toString().indexOf('_super') !== -1));
- if (concatenatedProperties && concatenatedProperties.indexOf(keyName) >= 0) {
+ if (concatenatedProperties && indexOf(concatenatedProperties, keyName) >= 0) {
var baseValue = this[keyName];
if (baseValue) { | false |
Other | emberjs | ember.js | d198eae4ce40e4884d5a2e76429c2d819e631503.json | Add view to active views in routes | packages/ember-routing/lib/system/route.js | @@ -85,6 +85,8 @@ Ember.Route = Ember.Object.extend({
className = classify(templateName),
view = container.lookup('view:' + templateName) || DefaultView.create();
+ this.router._activeViews[templateName] = view;
+
set(view, 'template', container.lookup('template:' + templateName));
options = options || {}; | false |
Other | emberjs | ember.js | c9edfccbcf3b172228d3e2ba85c3d2cc3a4ebe7a.json | use prop instead of attr to make git query happy | packages/ember-handlebars/tests/controls/select_test.js | @@ -591,7 +591,7 @@ test("select element should correctly initialize and update selectedIndex and bo
equal(selectEl.selectedIndex, 2, "Precond: The DOM reflects the correct selection");
select.$('option:eq(2)').removeAttr('selected');
- select.$('option:eq(1)').attr('selected', true);
+ select.$('option:eq(1)').prop('selected', true);
select.$().trigger('change');
equal(view.get('val'), 'w', "Updated bound property is correct"); | false |
Other | emberjs | ember.js | da2b2a0f2aa7586254985827555bf7722114be54.json | Pass the container and namespace into initializers | packages/ember-application/lib/system/application.js | @@ -430,6 +430,7 @@ var Application = Ember.Application = Ember.Namespace.extend(
runInitializers: function() {
var router = this.container.lookup('router:main'),
initializers = get(this.constructor, 'initializers'),
+ container = this.container,
graph = new Ember.DAG(),
namespace = this,
properties, i, initializer;
@@ -441,7 +442,7 @@ var Application = Ember.Application = Ember.Namespace.extend(
graph.topsort(function (vertex) {
var initializer = vertex.value;
- initializer(this.container);
+ initializer(container, namespace);
});
},
| false |
Other | emberjs | ember.js | 479d6bb6ec9d3dfc202a1576ff1e6d71009ede2c.json | Add linkTo test | packages/ember-routing/lib/handlebars_ext.js | @@ -72,3 +72,54 @@ Ember.onLoad('Ember.Handlebars', function(Handlebars) {
});
});
+
+function args(linkView) {
+ var ret = [ linkView.namedRoute ],
+ params = linkView.parameters,
+ contexts = params.contexts,
+ roots = params.roots,
+ data = params.data;
+
+ for (var i=0, l=contexts.length; i<l; i++) {
+ ret.push( Ember.Handlebars.get(roots[i], contexts[i], { data: data }) );
+ }
+
+ return ret;
+}
+
+var LinkView = Ember.View.extend({
+ tagName: 'a',
+ attributeBindings: 'href',
+
+ click: function() {
+ this.router.transitionTo.apply(this.router, args(this));
+ return false;
+ },
+
+ href: Ember.computed(function() {
+ // TODO: Fix this in route-recognizer
+ return this.router.generate.apply(this.router, args(this)) || "/";
+ })
+});
+
+LinkView.toString = function() { return "LinkView"; };
+
+Ember.Handlebars.registerHelper('linkTo', function(name) {
+ var options = [].slice.call(arguments, -1)[0];
+ var contexts = [].slice.call(arguments, 1, -1);
+
+ var hash = options.hash;
+
+ var controller = options.data.keywords.controller;
+ Ember.assert("You cannot use the {{linkTo}} helper because your current template does not have a controller", controller.target);
+
+ hash.namedRoute = name;
+ hash.router = controller.target;
+ hash.parameters = {
+ data: options.data,
+ contexts: contexts,
+ roots: options.contexts
+ };
+
+ return Ember.Handlebars.helpers.view.call(this, LinkView, options);
+}); | true |
Other | emberjs | ember.js | 479d6bb6ec9d3dfc202a1576ff1e6d71009ede2c.json | Add linkTo test | packages/ember-routing/lib/system/route.js | @@ -18,7 +18,9 @@ Ember.Route = Ember.Object.extend({
setup: function(context) {
var templateName = this.templateName,
controller = this.lookup('controller', templateName, function() {
- if (context) {
+ if (context && context.isSCArray) {
+ return Ember.ArrayController.create({ content: context });
+ } else if (context) {
return Ember.ObjectController.create({ content: context });
} else {
return Ember.Controller.create(); | true |
Other | emberjs | ember.js | 479d6bb6ec9d3dfc202a1576ff1e6d71009ede2c.json | Add linkTo test | packages/ember-routing/tests/helpers/link_to_test.js | @@ -0,0 +1,133 @@
+var Router, App, AppView, templates, router, eventDispatcher;
+var get = Ember.get, set = Ember.set;
+
+function bootApplication() {
+ router = Router.create({
+ location: 'none'
+ });
+
+ Ember.run(function() {
+ router._activeViews.application = AppView.create().appendTo('#qunit-fixture');
+ router.startRouting();
+ });
+}
+
+module("The {{linkTo}} helper", {
+ setup: function() {
+ Ember.run(function() {
+ App = Ember.Namespace.create();
+ App.toString = function() { return "App"; };
+
+ Ember.TEMPLATES.app = Ember.Handlebars.compile("{{outlet}}");
+ Ember.TEMPLATES.home = Ember.Handlebars.compile("<h3>Home</h3>{{#linkTo about id='about-link'}}About{{/linkTo}}");
+ Ember.TEMPLATES.about = Ember.Handlebars.compile("<h3>About</h3>{{#linkTo home id='home-link'}}Home{{/linkTo}}");
+ Ember.TEMPLATES.item = Ember.Handlebars.compile("<h3>Item</h3><p>{{name}}</p>{{#linkTo home id='home-link'}}Home{{/linkTo}}");
+
+ AppView = Ember.View.extend({
+ template: Ember.TEMPLATES.app
+ });
+
+ Router = Ember.Router.extend({
+ namespace: App,
+ templates: Ember.TEMPLATES
+ });
+
+ eventDispatcher = Ember.EventDispatcher.create();
+ eventDispatcher.setup();
+ });
+ },
+
+ teardown: function() {
+ Ember.run(function() { eventDispatcher.destroy(); });
+ }
+});
+
+test("The {{linkTo}} helper moves into the named route", function() {
+ Router.map(function(match) {
+ match("/").to("home");
+ match("/about").to("about");
+ });
+
+ bootApplication();
+
+ Ember.run(function() {
+ router.handleURL("/");
+ });
+
+ equal(Ember.$('h3:contains(Home)', '#qunit-fixture').length, 1, "The home template was rendered");
+
+ console.log(Ember.$('#qunit-fixture')[0]);
+
+ Ember.run(function() {
+ Ember.$('a', '#qunit-fixture').click();
+ });
+
+ equal(Ember.$('h3:contains(About)', '#qunit-fixture').length, 1, "The about template was rendered");
+});
+
+test("The {{linkTo}} helper moves into the named route with context", function() {
+ Router.map(function(match) {
+ match("/").to("home");
+ match("/about").to("about");
+ match("/item/:id").to("item");
+ });
+
+ Ember.TEMPLATES.about = Ember.Handlebars.compile("<h3>List</h3><ul>{{#each controller}}<li>{{#linkTo item this}}{{name}}{{/linkTo}}<li>{{/each}}</ul>{{#linkTo home id='home-link'}}Home{{/linkTo}}");
+
+ var people = {
+ yehuda: "Yehuda Katz",
+ tom: "Tom Dale",
+ erik: "Erik Brynroflsson"
+ };
+
+ App.AboutRoute = Ember.Route.extend({
+ model: function() {
+ return Ember.A([
+ { id: "yehuda", name: "Yehuda Katz" },
+ { id: "tom", name: "Tom Dale" },
+ { id: "erik", name: "Erik Brynroflsson" }
+ ]);
+ }
+ });
+
+ App.ItemRoute = Ember.Route.extend({
+ serialize: function(object) {
+ return { id: object.id };
+ },
+
+ deserialize: function(params) {
+ return { id: params.id, name: people[params.id] };
+ }
+ });
+
+ bootApplication();
+
+ Ember.run(function() {
+ router.handleURL("/about");
+ });
+
+ equal(Ember.$('h3:contains(List)', '#qunit-fixture').length, 1, "The home template was rendered");
+ equal(Ember.$('#home-link').attr('href'), '/', "The home link points back at /");
+
+ Ember.run(function() {
+ Ember.$('li a:contains(Yehuda)', '#qunit-fixture').click();
+ });
+
+ equal(Ember.$('h3:contains(Item)', '#qunit-fixture').length, 1, "The item template was rendered");
+ equal(Ember.$('p', '#qunit-fixture').text(), "Yehuda Katz", "The name is correct");
+
+ Ember.run(function() { Ember.$('#home-link').click(); });
+ Ember.run(function() { Ember.$('#about-link').click(); });
+
+ equal(Ember.$('li a:contains(Yehuda)').attr('href'), "/item/yehuda");
+ equal(Ember.$('li a:contains(Tom)').attr('href'), "/item/tom");
+ equal(Ember.$('li a:contains(Erik)').attr('href'), "/item/erik");
+
+ Ember.run(function() {
+ Ember.$('li a:contains(Erik)', '#qunit-fixture').click();
+ });
+
+ equal(Ember.$('h3:contains(Item)', '#qunit-fixture').length, 1, "The item template was rendered");
+ equal(Ember.$('p', '#qunit-fixture').text(), "Erik Brynroflsson", "The name is correct");
+});
+ | true |
Other | emberjs | ember.js | 479d6bb6ec9d3dfc202a1576ff1e6d71009ede2c.json | Add linkTo test | packages/ember-views/lib/views/view.js | @@ -864,9 +864,9 @@ Ember.View = Ember.CoreView.extend(
@type Object
*/
controller: Ember.computed(function(key) {
- var parentView = get(this, 'parentView');
+ var parentView = get(this, '_parentView');
return parentView ? get(parentView, 'controller') : null;
- }).property(),
+ }).property('_parentView'),
/**
A view may contain a layout. A layout is a regular template but | true |
Other | emberjs | ember.js | 9d13b7cf3dff1bd3298bbbe48da01d94bd848f56.json | Remove excessive instrumentation | packages/ember-handlebars/lib/helpers/binding.js | @@ -20,7 +20,6 @@ function bind(property, options, preserveContext, shouldDisplay, valueNormalizer
fn = options.fn,
inverse = options.inverse,
view = data.view,
- instrumentName = view.instrumentName,
currentContext = this,
pathRoot, path, normalized,
observer;
@@ -50,28 +49,23 @@ function bind(property, options, preserveContext, shouldDisplay, valueNormalizer
template(context, { data: options.data });
} else {
- var bindView = Ember.instrument('bind-view.' + instrumentName,
- { object: view.toString() },
- function() {
- // Create the view that will wrap the output of this template/property
- // and add it to the nearest view's childViews array.
- // See the documentation of Ember._HandlebarsBoundView for more.
- var bindView = view.createChildView(Ember._HandlebarsBoundView, {
- preserveContext: preserveContext,
- shouldDisplayFunc: shouldDisplay,
- valueNormalizerFunc: valueNormalizer,
- displayTemplate: fn,
- inverseTemplate: inverse,
- path: path,
- pathRoot: pathRoot,
- previousContext: currentContext,
- isEscaped: !options.hash.unescaped,
- templateData: options.data
- });
-
- view.appendChild(bindView);
- return bindView;
- });
+ // Create the view that will wrap the output of this template/property
+ // and add it to the nearest view's childViews array.
+ // See the documentation of Ember._HandlebarsBoundView for more.
+ var bindView = view.createChildView(Ember._HandlebarsBoundView, {
+ preserveContext: preserveContext,
+ shouldDisplayFunc: shouldDisplay,
+ valueNormalizerFunc: valueNormalizer,
+ displayTemplate: fn,
+ inverseTemplate: inverse,
+ path: path,
+ pathRoot: pathRoot,
+ previousContext: currentContext,
+ isEscaped: !options.hash.unescaped,
+ templateData: options.data
+ });
+
+ view.appendChild(bindView);
/** @private */
observer = function() {
@@ -100,7 +94,6 @@ function bind(property, options, preserveContext, shouldDisplay, valueNormalizer
function simpleBind(property, options) {
var data = options.data,
view = data.view,
- instrumentName = view.instrumentName,
currentContext = this,
pathRoot, path, normalized,
observer;
@@ -121,17 +114,12 @@ function simpleBind(property, options) {
if (result === null || result === undefined) { result = ""; }
data.buffer.push(result);
} else {
- var bindView = Ember.instrument('simple-bind-view.' + instrumentName,
- { object: view.toString() },
- function() {
- var bindView = new Ember._SimpleHandlebarsView(
- path, pathRoot, !options.hash.unescaped, options.data
- );
-
- bindView._parentView = view;
- view.appendChild(bindView);
- return bindView;
- });
+ var bindView = new Ember._SimpleHandlebarsView(
+ path, pathRoot, !options.hash.unescaped, options.data
+ );
+
+ bindView._parentView = view;
+ view.appendChild(bindView);
observer = function() {
Ember.run.scheduleOnce('render', bindView, 'rerender');
@@ -461,7 +449,7 @@ EmberHandlebars.registerHelper('bindAttr', function(options) {
Ember.assert("You must specify at least one hash argument to bindAttr", !!Ember.keys(attrs).length);
- var view = options.data.view, instrumentName = view.instrumentName;
+ var view = options.data.view;
var ret = [];
var ctx = this;
@@ -473,11 +461,7 @@ EmberHandlebars.registerHelper('bindAttr', function(options) {
// Handle classes differently, as we can bind multiple classes
var classBindings = attrs['class'];
if (classBindings !== null && classBindings !== undefined) {
- var classResults = Ember.instrument('class-bindings.' + instrumentName,
- { object: view.toString() },
- function() {
- return EmberHandlebars.bindClasses(this, classBindings, view, dataId, options);
- }, this);
+ var classResults = EmberHandlebars.bindClasses(this, classBindings, view, dataId, options);
ret.push('class="' + Handlebars.Utils.escapeExpression(classResults.join(' ')) + '"');
delete attrs['class']; | true |
Other | emberjs | ember.js | 9d13b7cf3dff1bd3298bbbe48da01d94bd848f56.json | Remove excessive instrumentation | packages/ember-handlebars/lib/helpers/collection.js | @@ -149,7 +149,6 @@ Ember.Handlebars.registerHelper('collection', function(path, options) {
var data = options.data;
var inverse = options.inverse;
var view = options.data.view;
- var instrumentName = view.instrumentName;
// If passed a path string, convert that into an object.
// Otherwise, just default to the standard class.
@@ -210,18 +209,9 @@ Ember.Handlebars.registerHelper('collection', function(path, options) {
var viewString = view.toString();
- Ember.instrument('collection-setup.' + instrumentName,
- { object: viewString },
- function() {
- var viewOptions = Ember.Handlebars.ViewHelper.propertiesFromHTMLOptions({ data: data, hash: itemHash }, this);
- viewOptions._anonymous = true;
- hash.itemViewClass = itemViewClass.extend(viewOptions);
- });
+ var viewOptions = Ember.Handlebars.ViewHelper.propertiesFromHTMLOptions({ data: data, hash: itemHash }, this);
+ hash.itemViewClass = itemViewClass.extend(viewOptions);
- return Ember.instrument('collection-view.' + instrumentName,
- { object: viewString },
- function() {
- return Ember.Handlebars.helpers.view.call(this, collectionClass, options);
- }, this);
+ return Ember.Handlebars.helpers.view.call(this, collectionClass, options);
});
| true |
Other | emberjs | ember.js | 9d13b7cf3dff1bd3298bbbe48da01d94bd848f56.json | Remove excessive instrumentation | packages/ember-handlebars/lib/views/handlebars_bound_view.js | @@ -51,16 +51,7 @@ SimpleHandlebarsView.prototype = {
return result;
},
- renderToBuffer: function(parentBuffer) {
- var name = 'render-to-buffer.simpleHandlebars',
- details = { object: '<Ember._SimpleHandlebarsView>' };
-
- return Ember.instrument(name, details, function() {
- return this._renderToBuffer(parentBuffer);
- }, this);
- },
-
- _renderToBuffer: function(buffer) {
+ renderToBuffer: function(buffer) {
var string = '';
string += this.morph.startTag(); | true |
Other | emberjs | ember.js | 9d13b7cf3dff1bd3298bbbe48da01d94bd848f56.json | Remove excessive instrumentation | packages/ember-views/lib/views/view.js | @@ -135,7 +135,7 @@ Ember.CoreView = Ember.Object.extend(Ember.Evented, {
be used.
*/
renderToBuffer: function(parentBuffer, bufferOperation) {
- var name = 'render-to-buffer.' + this.instrumentName,
+ var name = 'render.' + this.instrumentName,
details = {};
this.instrumentDetails(details);
@@ -1158,9 +1158,7 @@ Ember.View = Ember.CoreView.extend(
Ember.assert('template must be a function. Did you mean to call Ember.Handlebars.compile("...") or specify templateName instead?', typeof template === 'function');
// The template should write directly to the render buffer instead
// of returning a string.
- Ember.instrument('template.' + this.instrumentName,
- { object: this.toString() },
- function() { output = template(context, { data: data }); });
+ output = template(context, { data: data });
// If the template returned a string instead of writing to the buffer,
// push the string onto the buffer. | true |
Other | emberjs | ember.js | 50cfa59755418192c7f17a2564c7bea72c66811a.json | Remove excessive instrumentation | packages/ember-handlebars/lib/helpers/binding.js | @@ -20,7 +20,6 @@ function bind(property, options, preserveContext, shouldDisplay, valueNormalizer
fn = options.fn,
inverse = options.inverse,
view = data.view,
- instrumentName = view.instrumentName,
currentContext = this,
pathRoot, path, normalized,
observer;
@@ -50,28 +49,23 @@ function bind(property, options, preserveContext, shouldDisplay, valueNormalizer
template(context, { data: options.data });
} else {
- var bindView = Ember.instrument('bind-view.' + instrumentName,
- { object: view.toString() },
- function() {
- // Create the view that will wrap the output of this template/property
- // and add it to the nearest view's childViews array.
- // See the documentation of Ember._HandlebarsBoundView for more.
- var bindView = view.createChildView(Ember._HandlebarsBoundView, {
- preserveContext: preserveContext,
- shouldDisplayFunc: shouldDisplay,
- valueNormalizerFunc: valueNormalizer,
- displayTemplate: fn,
- inverseTemplate: inverse,
- path: path,
- pathRoot: pathRoot,
- previousContext: currentContext,
- isEscaped: !options.hash.unescaped,
- templateData: options.data
- });
-
- view.appendChild(bindView);
- return bindView;
- });
+ // Create the view that will wrap the output of this template/property
+ // and add it to the nearest view's childViews array.
+ // See the documentation of Ember._HandlebarsBoundView for more.
+ var bindView = view.createChildView(Ember._HandlebarsBoundView, {
+ preserveContext: preserveContext,
+ shouldDisplayFunc: shouldDisplay,
+ valueNormalizerFunc: valueNormalizer,
+ displayTemplate: fn,
+ inverseTemplate: inverse,
+ path: path,
+ pathRoot: pathRoot,
+ previousContext: currentContext,
+ isEscaped: !options.hash.unescaped,
+ templateData: options.data
+ });
+
+ view.appendChild(bindView);
/** @private */
observer = function() {
@@ -100,7 +94,6 @@ function bind(property, options, preserveContext, shouldDisplay, valueNormalizer
function simpleBind(property, options) {
var data = options.data,
view = data.view,
- instrumentName = view.instrumentName,
currentContext = this,
pathRoot, path, normalized,
observer;
@@ -121,17 +114,12 @@ function simpleBind(property, options) {
if (result === null || result === undefined) { result = ""; }
data.buffer.push(result);
} else {
- var bindView = Ember.instrument('simple-bind-view.' + instrumentName,
- { object: view.toString() },
- function() {
- var bindView = new Ember._SimpleHandlebarsView(
- path, pathRoot, !options.hash.unescaped, options.data
- );
-
- bindView._parentView = view;
- view.appendChild(bindView);
- return bindView;
- });
+ var bindView = new Ember._SimpleHandlebarsView(
+ path, pathRoot, !options.hash.unescaped, options.data
+ );
+
+ bindView._parentView = view;
+ view.appendChild(bindView);
observer = function() {
Ember.run.scheduleOnce('render', bindView, 'rerender');
@@ -461,7 +449,7 @@ EmberHandlebars.registerHelper('bindAttr', function(options) {
Ember.assert("You must specify at least one hash argument to bindAttr", !!Ember.keys(attrs).length);
- var view = options.data.view, instrumentName = view.instrumentName;
+ var view = options.data.view;
var ret = [];
var ctx = this;
@@ -473,11 +461,7 @@ EmberHandlebars.registerHelper('bindAttr', function(options) {
// Handle classes differently, as we can bind multiple classes
var classBindings = attrs['class'];
if (classBindings !== null && classBindings !== undefined) {
- var classResults = Ember.instrument('class-bindings.' + instrumentName,
- { object: view.toString() },
- function() {
- return EmberHandlebars.bindClasses(this, classBindings, view, dataId, options);
- }, this);
+ var classResults = EmberHandlebars.bindClasses(this, classBindings, view, dataId, options);
ret.push('class="' + Handlebars.Utils.escapeExpression(classResults.join(' ')) + '"');
delete attrs['class']; | true |
Other | emberjs | ember.js | 50cfa59755418192c7f17a2564c7bea72c66811a.json | Remove excessive instrumentation | packages/ember-handlebars/lib/helpers/collection.js | @@ -149,7 +149,6 @@ Ember.Handlebars.registerHelper('collection', function(path, options) {
var data = options.data;
var inverse = options.inverse;
var view = options.data.view;
- var instrumentName = view.instrumentName;
// If passed a path string, convert that into an object.
// Otherwise, just default to the standard class.
@@ -210,18 +209,9 @@ Ember.Handlebars.registerHelper('collection', function(path, options) {
var viewString = view.toString();
- Ember.instrument('collection-setup.' + instrumentName,
- { object: viewString },
- function() {
- var viewOptions = Ember.Handlebars.ViewHelper.propertiesFromHTMLOptions({ data: data, hash: itemHash }, this);
- viewOptions._anonymous = true;
- hash.itemViewClass = itemViewClass.extend(viewOptions);
- });
+ var viewOptions = Ember.Handlebars.ViewHelper.propertiesFromHTMLOptions({ data: data, hash: itemHash }, this);
+ hash.itemViewClass = itemViewClass.extend(viewOptions);
- return Ember.instrument('collection-view.' + instrumentName,
- { object: viewString },
- function() {
- return Ember.Handlebars.helpers.view.call(this, collectionClass, options);
- }, this);
+ return Ember.Handlebars.helpers.view.call(this, collectionClass, options);
});
| true |
Other | emberjs | ember.js | 50cfa59755418192c7f17a2564c7bea72c66811a.json | Remove excessive instrumentation | packages/ember-handlebars/lib/views/handlebars_bound_view.js | @@ -51,16 +51,7 @@ SimpleHandlebarsView.prototype = {
return result;
},
- renderToBuffer: function(parentBuffer) {
- var name = 'render-to-buffer.simpleHandlebars',
- details = { object: '<Ember._SimpleHandlebarsView>' };
-
- return Ember.instrument(name, details, function() {
- return this._renderToBuffer(parentBuffer);
- }, this);
- },
-
- _renderToBuffer: function(buffer) {
+ renderToBuffer: function(buffer) {
var string = '';
string += this.morph.startTag(); | true |
Other | emberjs | ember.js | 50cfa59755418192c7f17a2564c7bea72c66811a.json | Remove excessive instrumentation | packages/ember-views/lib/views/view.js | @@ -135,7 +135,7 @@ Ember.CoreView = Ember.Object.extend(Ember.Evented, {
be used.
*/
renderToBuffer: function(parentBuffer, bufferOperation) {
- var name = 'render-to-buffer.' + this.instrumentName,
+ var name = 'render.' + this.instrumentName,
details = {};
this.instrumentDetails(details);
@@ -1158,9 +1158,7 @@ Ember.View = Ember.CoreView.extend(
Ember.assert('template must be a function. Did you mean to call Ember.Handlebars.compile("...") or specify templateName instead?', typeof template === 'function');
// The template should write directly to the render buffer instead
// of returning a string.
- Ember.instrument('template.' + this.instrumentName,
- { object: this.toString() },
- function() { output = template(context, { data: data }); });
+ output = template(context, { data: data });
// If the template returned a string instead of writing to the buffer,
// push the string onto the buffer. | true |
Other | emberjs | ember.js | ab469a432a33740f3c182ee36304bcd2b87c7469.json | Move tests to ember-old-router | packages/ember-old-router/tests/application_test.js | @@ -0,0 +1,46 @@
+require('ember-application');
+
+var set = Ember.set, get = Ember.get;
+var app;
+
+module("Ember.Application initialization", {
+ teardown: function() {
+ Ember.run(function(){ app.destroy(); });
+ }
+});
+
+test('initialized application go to initial route', function() {
+ Ember.run(function() {
+ app = Ember.Application.create({
+ rootElement: '#qunit-fixture'
+ });
+
+ app.stateManager = Ember.Router.create({
+ location: {
+ getURL: function() {
+ return '/';
+ },
+ setURL: function() {},
+ onUpdateURL: function() {}
+ },
+
+ root: Ember.Route.extend({
+ index: Ember.Route.extend({
+ route: '/'
+ })
+ })
+ });
+
+
+ app.ApplicationView = Ember.View.extend({
+ template: function() { return "Hello!"; }
+ });
+
+ app.ApplicationController = Ember.Controller.extend();
+
+ Ember.run(function() { app.initialize(app.stateManager); });
+ });
+
+ equal(app.get('router.currentState.path'), 'root.index', "The router moved the state into the right place");
+});
+ | true |
Other | emberjs | ember.js | ab469a432a33740f3c182ee36304bcd2b87c7469.json | Move tests to ember-old-router | packages/ember-old-router/tests/helpers/action_test.js | @@ -0,0 +1,116 @@
+var namespace = {
+ "Component": {
+ toString: function() { return "Component"; },
+ find: function() { return { id: 1 }; }
+ }
+};
+
+var compile = function(string) {
+ return Ember.Handlebars.compile(string);
+};
+
+test("it sets an URL with a context", function() {
+ var router = Ember.Router.create({
+ location: {
+ formatURL: function(url) {
+ return url;
+ },
+ setURL: Ember.K
+ },
+ namespace: namespace,
+ root: Ember.Route.create({
+ index: Ember.Route.create({
+ route: '/',
+
+ showDashboard: function(router) {
+ router.transitionTo('dashboard');
+ },
+
+ eventTransitions: {
+ showDashboard: 'dashboard'
+ }
+ }),
+
+ dashboard: Ember.Route.create({
+ route: '/dashboard/:component_id'
+ })
+ })
+ });
+
+ Ember.run(function() {
+ router.route("/");
+ });
+
+ equal(router.get('currentState.path'), "root.index", "precond - the current stat is root.index");
+
+ var view = Ember.View.create({
+ template: compile('<a {{action showDashboard controller.component href=true}}>test</a>')
+ });
+
+ var controller = {
+ target: router,
+ component: { id: 1 }
+ };
+
+ Ember.run(function() {
+ view.set('controller', controller);
+ view.appendTo('#qunit-fixture');
+ });
+
+ ok(view.$().html().match(/href=['"].*\/dashboard\/1['"]/), "The html (" + view.$().html() + ") has the href /dashboard/1 in it");
+});
+
+test("it does not trigger action with special clicks", function() {
+ var dispatcher = Ember.EventDispatcher.create();
+ dispatcher.setup();
+
+ var showCalled = false;
+
+ var view = Ember.View.create({
+ template: compile("<a {{action show href=true}}>Hi</a>")
+ });
+
+ var controller = Ember.Object.create(Ember.ControllerMixin, {
+ target: {
+ urlForEvent: function(event, context) {
+ return "/foo/bar";
+ },
+
+ show: function() {
+ showCalled = true;
+ }
+ }
+ });
+
+ Ember.run(function() {
+ view.set('controller', controller);
+ view.appendTo('#qunit-fixture');
+ });
+
+ function checkClick(prop, value, expected) {
+ var event = Ember.$.Event("click");
+ event[prop] = value;
+ view.$('a').trigger(event);
+ if (expected) {
+ ok(showCalled, "should call action with "+prop+":"+value);
+ ok(event.isDefaultPrevented(), "should prevent default");
+ } else {
+ ok(!showCalled, "should not call action with "+prop+":"+value);
+ ok(!event.isDefaultPrevented(), "should not prevent default");
+ }
+ }
+
+ checkClick('ctrlKey', true, false);
+ checkClick('altKey', true, false);
+ checkClick('metaKey', true, false);
+ checkClick('shiftKey', true, false);
+ checkClick('which', 2, false);
+
+ checkClick('which', 1, true);
+ checkClick('which', undefined, true); // IE <9
+
+ Ember.run(function() {
+ dispatcher.destroy();
+ });
+});
+ | true |
Other | emberjs | ember.js | cd2645c15c173745d52fd9539e7cef87b3126059.json | Remove straggling test | packages/ember-views/tests/views/view/nearest_view_test.js | @@ -1,92 +0,0 @@
-var set = Ember.set, get = Ember.get;
-
-module("Ember.View nearest view helpers");
-
-test("collectionView should return the nearest collection view", function() {
- var itemViewChild;
-
- var view = Ember.CollectionView.create({
- content: Ember.A([1, 2, 3]),
- isARealCollection: true,
-
- itemViewClass: Ember.View.extend({
- render: function(buffer) {
- this.appendChild(Ember.View.create());
- }
- })
- });
-
- Ember.run(function() {
- view.appendTo('#qunit-fixture');
- });
-
- itemViewChild = view.get('childViews')[0].get('childViews')[0];
- equal(itemViewChild.get('collectionView.isARealCollection'), true, "finds collection view in the hierarchy");
-});
-
-test("itemView should return the nearest child of a collection view", function() {
- var itemViewChild;
-
- var view = Ember.CollectionView.create({
- content: Ember.A([1, 2, 3]),
-
- itemViewClass: Ember.View.extend({
- isAnItemView: true,
-
- render: function(buffer) {
- this.appendChild(Ember.View.create());
- }
- })
- });
-
- Ember.run(function() {
- view.appendTo('#qunit-fixture');
- });
-
- itemViewChild = view.get('childViews')[0].get('childViews')[0];
- equal(itemViewChild.get('itemView.isAnItemView'), true, "finds item view in the hierarchy");
-});
-
-test("itemView should return the nearest child of a collection view", function() {
- var itemViewChild;
-
- var view = Ember.CollectionView.create({
- content: Ember.A([1, 2, 3]),
-
- itemViewClass: Ember.View.extend({
- isAnItemView: true,
-
- render: function(buffer) {
- this.appendChild(Ember.View.create());
- }
- })
- });
-
- Ember.run(function() {
- view.appendTo('#qunit-fixture');
- });
-
- itemViewChild = view.get('childViews')[0].get('childViews')[0];
- equal(itemViewChild.get('contentView.isAnItemView'), true, "finds a view with a content property in the hierarchy");
-});
-
-test("nearestWithProperty should search immediate parent", function(){
- var childView;
-
- var view = Ember.View.create({
- myProp: true,
-
- render: function(buffer) {
- this.appendChild(Ember.View.create());
- }
- });
-
- Ember.run(function() {
- view.appendTo('#qunit-fixture');
- });
-
- childView = view.get('childViews')[0];
- equal(childView.nearestWithProperty('myProp'), view);
-
-});
- | false |
Other | emberjs | ember.js | 4f651930b51756388b6aa7517f550f3aca769d01.json | Remove the nearest view computed properties
(but leave the method-style lookups) | packages/ember-views/lib/views/view.js | @@ -1082,38 +1082,6 @@ Ember.View = Ember.CoreView.extend(
}
},
- /**
- Return the nearest ancestor that is an `Ember.CollectionView`
-
- @property collectionView
- @return Ember.CollectionView
- */
- collectionView: Ember.computed(function() {
- return this.nearestOfType(Ember.CollectionView);
- }),
-
- /**
- Return the nearest ancestor that is a direct child of
- an `Ember.CollectionView`
-
- @property itemView
- @return Ember.View
- */
- itemView: Ember.computed(function() {
- return this.nearestChildOf(Ember.CollectionView);
- }),
-
- /**
- Return the nearest ancestor that has the property
- `content`.
-
- @property contentView
- @return Ember.View
- */
- contentView: Ember.computed(function() {
- return this.nearestWithProperty('content');
- }),
-
/**
@private
@@ -1125,12 +1093,6 @@ Ember.View = Ember.CoreView.extend(
_parentViewDidChange: Ember.observer(function() {
if (this.isDestroying) { return; }
- this.invokeRecursively(function(view) {
- view.propertyDidChange('collectionView');
- view.propertyDidChange('itemView');
- view.propertyDidChange('contentView');
- });
-
if (get(this, 'parentView.controller') && !get(this, 'controller')) {
this.notifyPropertyChange('controller');
} | true |
Other | emberjs | ember.js | 4f651930b51756388b6aa7517f550f3aca769d01.json | Remove the nearest view computed properties
(but leave the method-style lookups) | packages/ember-views/tests/views/view/nearest_of_type_test.js | @@ -1,6 +1,6 @@
var set = Ember.set, get = Ember.get;
-module("Ember.View#nearestOfType");
+module("Ember.View#nearest*");
(function() {
var Mixin = Ember.Mixin.create({}),
@@ -34,4 +34,24 @@ module("Ember.View#nearestOfType");
equal(child.nearestOfType(Mixin), parent, "finds closest view in the hierarchy by class");
});
-}());
\ No newline at end of file
+test("nearestWithProperty should search immediate parent", function(){
+ var childView;
+
+ var view = Ember.View.create({
+ myProp: true,
+
+ render: function(buffer) {
+ this.appendChild(Ember.View.create());
+ }
+ });
+
+ Ember.run(function() {
+ view.appendTo('#qunit-fixture');
+ });
+
+ childView = view.get('childViews')[0];
+ equal(childView.nearestWithProperty('myProp'), view);
+
+});
+
+}()); | true |
Other | emberjs | ember.js | b7b832437a896a02180ec59ef490c4c14b832ffc.json | Add a views test suite from rake | Rakefile | @@ -75,6 +75,7 @@ task :test, [:suite] => :dist do |t, args|
suites = {
:default => packages.map{|p| "package=#{p}" },
:runtime => [ "package=ember-metal,ember-runtime" ],
+ :views => [ "package=ember-views,ember-handlebars" ],
:all => packages.map{|p| "package=#{p}" } +
["package=all&jquery=1.7.2&nojshint=true",
"package=all&jquery=git&nojshint=true", | false |
Other | emberjs | ember.js | 8bb14d5e3b50abc58d7ed9b053709e604070de00.json | Move location to ember-routing | packages/ember-routing/lib/location.js | @@ -0,0 +1,5 @@
+require('ember-views');
+require('ember-routing/location/api');
+require('ember-routing/location/none_location');
+require('ember-routing/location/hash_location');
+require('ember-routing/location/history_location'); | true |
Other | emberjs | ember.js | 8bb14d5e3b50abc58d7ed9b053709e604070de00.json | Move location to ember-routing | packages/ember-routing/lib/location/api.js | @@ -0,0 +1,50 @@
+/**
+@module ember
+@submodule ember-old-router
+*/
+
+var get = Ember.get, set = Ember.set;
+
+/*
+ This file implements the `location` API used by Ember's router.
+
+ That API is:
+
+ getURL: returns the current URL
+ setURL(path): sets the current URL
+ onUpdateURL(callback): triggers the callback when the URL changes
+ formatURL(url): formats `url` to be placed into `href` attribute
+
+ Calling setURL will not trigger onUpdateURL callbacks.
+
+ TODO: This should perhaps be moved so that it's visible in the doc output.
+*/
+
+/**
+ Ember.Location returns an instance of the correct implementation of
+ the `location` API.
+
+ You can pass it a `implementation` ('hash', 'history', 'none') to force a
+ particular implementation.
+
+ @class Location
+ @namespace Ember
+ @static
+*/
+Ember.Location = {
+ create: function(options) {
+ var implementation = options && options.implementation;
+ Ember.assert("Ember.Location.create: you must specify a 'implementation' option", !!implementation);
+
+ var implementationClass = this.implementations[implementation];
+ Ember.assert("Ember.Location.create: " + implementation + " is not a valid implementation", !!implementationClass);
+
+ return implementationClass.create.apply(implementationClass, arguments);
+ },
+
+ registerImplementation: function(name, implementation) {
+ this.implementations[name] = implementation;
+ },
+
+ implementations: {}
+}; | true |
Other | emberjs | ember.js | 8bb14d5e3b50abc58d7ed9b053709e604070de00.json | Move location to ember-routing | packages/ember-routing/lib/location/hash_location.js | @@ -0,0 +1,96 @@
+/**
+@module ember
+@submodule ember-old-router
+*/
+
+var get = Ember.get, set = Ember.set;
+
+/**
+ Ember.HashLocation implements the location API using the browser's
+ hash. At present, it relies on a hashchange event existing in the
+ browser.
+
+ @class HashLocation
+ @namespace Ember
+ @extends Ember.Object
+*/
+Ember.HashLocation = Ember.Object.extend({
+
+ init: function() {
+ set(this, 'location', get(this, 'location') || window.location);
+ },
+
+ /**
+ @private
+
+ Returns the current `location.hash`, minus the '#' at the front.
+
+ @method getURL
+ */
+ getURL: function() {
+ return get(this, 'location').hash.substr(1);
+ },
+
+ /**
+ @private
+
+ Set the `location.hash` and remembers what was set. This prevents
+ `onUpdateURL` callbacks from triggering when the hash was set by
+ `HashLocation`.
+
+ @method setURL
+ @param path {String}
+ */
+ setURL: function(path) {
+ get(this, 'location').hash = path;
+ set(this, 'lastSetURL', path);
+ },
+
+ /**
+ @private
+
+ Register a callback to be invoked when the hash changes. These
+ callbacks will execute when the user presses the back or forward
+ button, but not after `setURL` is invoked.
+
+ @method onUpdateURL
+ @param callback {Function}
+ */
+ onUpdateURL: function(callback) {
+ var self = this;
+ var guid = Ember.guidFor(this);
+
+ Ember.$(window).bind('hashchange.ember-location-'+guid, function() {
+ var path = location.hash.substr(1);
+ if (get(self, 'lastSetURL') === path) { return; }
+
+ set(self, 'lastSetURL', null);
+
+ callback(location.hash.substr(1));
+ });
+ },
+
+ /**
+ @private
+
+ Given a URL, formats it to be placed into the page as part
+ of an element's `href` attribute.
+
+ This is used, for example, when using the {{action}} helper
+ to generate a URL based on an event.
+
+ @method formatURL
+ @param url {String}
+ */
+ formatURL: function(url) {
+ return '#'+url;
+ },
+
+ willDestroy: function() {
+ var guid = Ember.guidFor(this);
+
+ Ember.$(window).unbind('hashchange.ember-location-'+guid);
+ }
+});
+
+Ember.Location.registerImplementation('hash', Ember.HashLocation); | true |
Other | emberjs | ember.js | 8bb14d5e3b50abc58d7ed9b053709e604070de00.json | Move location to ember-routing | packages/ember-routing/lib/location/history_location.js | @@ -0,0 +1,152 @@
+/**
+@module ember
+@submodule ember-old-router
+*/
+
+var get = Ember.get, set = Ember.set;
+var popstateReady = false;
+
+/**
+ Ember.HistoryLocation implements the location API using the browser's
+ history.pushState API.
+
+ @class HistoryLocation
+ @namespace Ember
+ @extends Ember.Object
+*/
+Ember.HistoryLocation = Ember.Object.extend({
+
+ init: function() {
+ set(this, 'location', get(this, 'location') || window.location);
+ this.initState();
+ },
+
+ /**
+ @private
+
+ Used to set state on first call to setURL
+
+ @method initState
+ */
+ initState: function() {
+ this.replaceState(get(this, 'location').pathname);
+ set(this, 'history', window.history);
+ },
+
+ /**
+ Will be pre-pended to path upon state change
+
+ @property rootURL
+ @default '/'
+ */
+ rootURL: '/',
+
+ /**
+ @private
+
+ Returns the current `location.pathname`.
+
+ @method getURL
+ */
+ getURL: function() {
+ return get(this, 'location').pathname;
+ },
+
+ /**
+ @private
+
+ Uses `history.pushState` to update the url without a page reload.
+
+ @method setURL
+ @param path {String}
+ */
+ setURL: function(path) {
+ path = this.formatURL(path);
+
+ if (this.getState() && this.getState().path !== path) {
+ popstateReady = true;
+ this.pushState(path);
+ }
+ },
+
+ /**
+ @private
+
+ Get the current `history.state`
+
+ @method getState
+ */
+ getState: function() {
+ return get(this, 'history').state;
+ },
+
+ /**
+ @private
+
+ Pushes a new state
+
+ @method pushState
+ @param path {String}
+ */
+ pushState: function(path) {
+ window.history.pushState({ path: path }, null, path);
+ },
+
+ /**
+ @private
+
+ Replaces the current state
+
+ @method replaceState
+ @param path {String}
+ */
+ replaceState: function(path) {
+ window.history.replaceState({ path: path }, null, path);
+ },
+
+ /**
+ @private
+
+ Register a callback to be invoked whenever the browser
+ history changes, including using forward and back buttons.
+
+ @method onUpdateURL
+ @param callback {Function}
+ */
+ onUpdateURL: function(callback) {
+ var guid = Ember.guidFor(this);
+
+ Ember.$(window).bind('popstate.ember-location-'+guid, function(e) {
+ if(!popstateReady) {
+ return;
+ }
+ callback(location.pathname);
+ });
+ },
+
+ /**
+ @private
+
+ Used when using `{{action}}` helper. The url is always appended to the rootURL.
+
+ @method formatURL
+ @param url {String}
+ */
+ formatURL: function(url) {
+ var rootURL = get(this, 'rootURL');
+
+ if (url !== '') {
+ rootURL = rootURL.replace(/\/$/, '');
+ }
+
+ return rootURL + url;
+ },
+
+ willDestroy: function() {
+ var guid = Ember.guidFor(this);
+
+ Ember.$(window).unbind('popstate.ember-location-'+guid);
+ }
+});
+
+Ember.Location.registerImplementation('history', Ember.HistoryLocation); | true |
Other | emberjs | ember.js | 8bb14d5e3b50abc58d7ed9b053709e604070de00.json | Move location to ember-routing | packages/ember-routing/lib/location/none_location.js | @@ -0,0 +1,41 @@
+/**
+@module ember
+@submodule ember-old-router
+*/
+
+var get = Ember.get, set = Ember.set;
+
+/**
+ Ember.NoneLocation does not interact with the browser. It is useful for
+ testing, or when you need to manage state with your Router, but temporarily
+ don't want it to muck with the URL (for example when you embed your
+ application in a larger page).
+
+ @class NoneLocation
+ @namespace Ember
+ @extends Ember.Object
+*/
+Ember.NoneLocation = Ember.Object.extend({
+ path: '',
+
+ getURL: function() {
+ return get(this, 'path');
+ },
+
+ setURL: function(path) {
+ set(this, 'path', path);
+ },
+
+ onUpdateURL: function(callback) {
+ // We are not wired up to the browser, so we'll never trigger the callback.
+ },
+
+ formatURL: function(url) {
+ // The return value is not overly meaningful, but we do not want to throw
+ // errors when test code renders templates containing {{action href=true}}
+ // helpers.
+ return url;
+ }
+});
+
+Ember.Location.registerImplementation('none', Ember.NoneLocation); | true |
Other | emberjs | ember.js | aa3cb1eeac5ebe2e85b3bebf0b9f458d9b38237e.json | Remove straggling test | packages/ember-views/tests/views/view/nearest_view_test.js | @@ -1,92 +0,0 @@
-var set = Ember.set, get = Ember.get;
-
-module("Ember.View nearest view helpers");
-
-test("collectionView should return the nearest collection view", function() {
- var itemViewChild;
-
- var view = Ember.CollectionView.create({
- content: Ember.A([1, 2, 3]),
- isARealCollection: true,
-
- itemViewClass: Ember.View.extend({
- render: function(buffer) {
- this.appendChild(Ember.View.create());
- }
- })
- });
-
- Ember.run(function() {
- view.appendTo('#qunit-fixture');
- });
-
- itemViewChild = view.get('childViews')[0].get('childViews')[0];
- equal(itemViewChild.get('collectionView.isARealCollection'), true, "finds collection view in the hierarchy");
-});
-
-test("itemView should return the nearest child of a collection view", function() {
- var itemViewChild;
-
- var view = Ember.CollectionView.create({
- content: Ember.A([1, 2, 3]),
-
- itemViewClass: Ember.View.extend({
- isAnItemView: true,
-
- render: function(buffer) {
- this.appendChild(Ember.View.create());
- }
- })
- });
-
- Ember.run(function() {
- view.appendTo('#qunit-fixture');
- });
-
- itemViewChild = view.get('childViews')[0].get('childViews')[0];
- equal(itemViewChild.get('itemView.isAnItemView'), true, "finds item view in the hierarchy");
-});
-
-test("itemView should return the nearest child of a collection view", function() {
- var itemViewChild;
-
- var view = Ember.CollectionView.create({
- content: Ember.A([1, 2, 3]),
-
- itemViewClass: Ember.View.extend({
- isAnItemView: true,
-
- render: function(buffer) {
- this.appendChild(Ember.View.create());
- }
- })
- });
-
- Ember.run(function() {
- view.appendTo('#qunit-fixture');
- });
-
- itemViewChild = view.get('childViews')[0].get('childViews')[0];
- equal(itemViewChild.get('contentView.isAnItemView'), true, "finds a view with a content property in the hierarchy");
-});
-
-test("nearestWithProperty should search immediate parent", function(){
- var childView;
-
- var view = Ember.View.create({
- myProp: true,
-
- render: function(buffer) {
- this.appendChild(Ember.View.create());
- }
- });
-
- Ember.run(function() {
- view.appendTo('#qunit-fixture');
- });
-
- childView = view.get('childViews')[0];
- equal(childView.nearestWithProperty('myProp'), view);
-
-});
- | false |
Other | emberjs | ember.js | 558b888b6eb27333f919749a03e956248771d2dc.json | Remove the nearest view computed properties
(but leave the method-style lookups) | packages/ember-views/lib/views/view.js | @@ -1082,38 +1082,6 @@ Ember.View = Ember.CoreView.extend(
}
},
- /**
- Return the nearest ancestor that is an `Ember.CollectionView`
-
- @property collectionView
- @return Ember.CollectionView
- */
- collectionView: Ember.computed(function() {
- return this.nearestOfType(Ember.CollectionView);
- }),
-
- /**
- Return the nearest ancestor that is a direct child of
- an `Ember.CollectionView`
-
- @property itemView
- @return Ember.View
- */
- itemView: Ember.computed(function() {
- return this.nearestChildOf(Ember.CollectionView);
- }),
-
- /**
- Return the nearest ancestor that has the property
- `content`.
-
- @property contentView
- @return Ember.View
- */
- contentView: Ember.computed(function() {
- return this.nearestWithProperty('content');
- }),
-
/**
@private
@@ -1125,12 +1093,6 @@ Ember.View = Ember.CoreView.extend(
_parentViewDidChange: Ember.observer(function() {
if (this.isDestroying) { return; }
- this.invokeRecursively(function(view) {
- view.propertyDidChange('collectionView');
- view.propertyDidChange('itemView');
- view.propertyDidChange('contentView');
- });
-
if (get(this, 'parentView.controller') && !get(this, 'controller')) {
this.notifyPropertyChange('controller');
} | true |
Other | emberjs | ember.js | 558b888b6eb27333f919749a03e956248771d2dc.json | Remove the nearest view computed properties
(but leave the method-style lookups) | packages/ember-views/tests/views/view/nearest_of_type_test.js | @@ -1,6 +1,6 @@
var set = Ember.set, get = Ember.get;
-module("Ember.View#nearestOfType");
+module("Ember.View#nearest*");
(function() {
var Mixin = Ember.Mixin.create({}),
@@ -34,4 +34,24 @@ module("Ember.View#nearestOfType");
equal(child.nearestOfType(Mixin), parent, "finds closest view in the hierarchy by class");
});
-}());
\ No newline at end of file
+test("nearestWithProperty should search immediate parent", function(){
+ var childView;
+
+ var view = Ember.View.create({
+ myProp: true,
+
+ render: function(buffer) {
+ this.appendChild(Ember.View.create());
+ }
+ });
+
+ Ember.run(function() {
+ view.appendTo('#qunit-fixture');
+ });
+
+ childView = view.get('childViews')[0];
+ equal(childView.nearestWithProperty('myProp'), view);
+
+});
+
+}()); | true |
Other | emberjs | ember.js | cadc544ba17471d12a7b58f07a6577f94569b53f.json | Add a views test suite from rake | Rakefile | @@ -75,6 +75,7 @@ task :test, [:suite] => :dist do |t, args|
suites = {
:default => packages.map{|p| "package=#{p}" },
:runtime => [ "package=ember-metal,ember-runtime" ],
+ :views => [ "package=ember-views,ember-handlebars" ],
:all => packages.map{|p| "package=#{p}" } +
["package=all&jquery=1.7.2&nojshint=true",
"package=all&jquery=git&nojshint=true", | false |
Other | emberjs | ember.js | 4df1d40e5b650fa20c598b36f5da14e7ab2aa5e9.json | change bindingContext to context | packages/ember-handlebars/lib/helpers/view.js | @@ -82,18 +82,14 @@ EmberHandlebars.ViewHelper = Ember.Object.create({
//
// is converted to this:
//
- // classNameBinding="bindingContext.isGreen:green"
+ // classNameBinding="context.isGreen:green"
var parsedPath = Ember.View._parsePropertyPath(full);
path = this.contextualizeBindingPath(parsedPath.path, data);
if (path) { extensions.classNameBindings[b] = path + parsedPath.classNames; }
}
}
}
- // Make the current template context available to the view
- // for the bindings set up above.
- extensions.bindingContext = thisContext;
-
return Ember.$.extend(hash, extensions);
},
@@ -108,9 +104,9 @@ EmberHandlebars.ViewHelper = Ember.Object.create({
} else if (Ember.isGlobalPath(path)) {
return null;
} else if (path === 'this') {
- return 'bindingContext';
+ return 'context';
} else {
- return 'bindingContext.' + path;
+ return 'context.' + path;
}
},
| true |
Other | emberjs | ember.js | 4df1d40e5b650fa20c598b36f5da14e7ab2aa5e9.json | change bindingContext to context | packages/ember-handlebars/tests/handlebars_test.js | @@ -2351,7 +2351,7 @@ test("should accept bindings as a string or an Ember.Binding", function() {
Ember.Handlebars.registerHelper('boogie', function(id, options) {
options.hash = options.hash || {};
- options.hash.bindingTestBinding = Ember.Binding.oneWay('bindingContext.' + id);
+ options.hash.bindingTestBinding = Ember.Binding.oneWay('context.' + id);
options.hash.stringTestBinding = id;
return Ember.Handlebars.ViewHelper.helper(this, viewClass, options);
}); | true |
Other | emberjs | ember.js | c1c720781c976f69fd4014ea50a1fee652286048.json | Change the behavior of Ember.Object.create().
The prior create behavior is available as
Ember.Object.createWithMixins().
We suggest using Ember.Object.extend() to create classes and use create
to initialize properties on your instance.
The new behavior will call computed property setters instead of
overwriting them. This was commonly worked around by calling
setProperties immediately after create.
This improves performance of object creation by 2x. | packages/ember-handlebars/tests/controls/text_area_test.js | @@ -125,7 +125,7 @@ test("input tabindex is updated when setting tabindex property of view", functio
test("value binding works properly for inputs that haven't been created", function() {
Ember.run(function() {
- textArea = Ember.TextArea.create({
+ textArea = Ember.TextArea.createWithMixins({
valueBinding: 'TestObject.value'
});
}); | true |
Other | emberjs | ember.js | c1c720781c976f69fd4014ea50a1fee652286048.json | Change the behavior of Ember.Object.create().
The prior create behavior is available as
Ember.Object.createWithMixins().
We suggest using Ember.Object.extend() to create classes and use create
to initialize properties on your instance.
The new behavior will call computed property setters instead of
overwriting them. This was commonly worked around by calling
setProperties immediately after create.
This improves performance of object creation by 2x. | packages/ember-handlebars/tests/controls/text_field_test.js | @@ -121,7 +121,7 @@ test("input type is configurable when creating view", function() {
test("value binding works properly for inputs that haven't been created", function() {
Ember.run(function() {
- textField = Ember.TextField.create({
+ textField = Ember.TextField.createWithMixins({
valueBinding: 'TestObject.value'
});
}); | true |
Other | emberjs | ember.js | c1c720781c976f69fd4014ea50a1fee652286048.json | Change the behavior of Ember.Object.create().
The prior create behavior is available as
Ember.Object.createWithMixins().
We suggest using Ember.Object.extend() to create classes and use create
to initialize properties on your instance.
The new behavior will call computed property setters instead of
overwriting them. This was commonly worked around by calling
setProperties immediately after create.
This improves performance of object creation by 2x. | packages/ember-handlebars/tests/handlebars_test.js | @@ -103,7 +103,7 @@ test("template view should call the function of the associated template", functi
});
test("template view should call the function of the associated template with itself as the context", function() {
- view = Ember.View.create({
+ view = Ember.View.createWithMixins({
templateName: 'test_template',
_personName: "Tom DAAAALE",
@@ -1331,7 +1331,7 @@ test("should be able to bind element attributes using {{bindAttr}}", function()
equal(view.$('img').attr('alt'), "The SproutCore Logo", "updates alt attribute when content object is a hash");
Ember.run(function() {
- set(view, 'content', Ember.Object.create({
+ set(view, 'content', Ember.Object.createWithMixins({
url: "http://www.emberjs.com/assets/images/logo.png",
title: Ember.computed(function() {
return "Nanananana Ember!";
@@ -1433,7 +1433,7 @@ test("should be able to bind use {{bindAttr}} more than once on an element", fun
equal(view.$('img').attr('alt'), "The SproutCore Logo", "updates alt attribute when content object is a hash");
Ember.run(function() {
- set(view, 'content', Ember.Object.create({
+ set(view, 'content', Ember.Object.createWithMixins({
url: "http://www.emberjs.com/assets/images/logo.png",
title: Ember.computed(function() {
return "Nanananana Ember!";
@@ -2332,7 +2332,7 @@ test("should call a registered helper for mustache without parameters", function
});
test("should bind to the property if no registered helper found for a mustache without parameters", function() {
- view = Ember.View.create({
+ view = Ember.View.createWithMixins({
template: Ember.Handlebars.compile("{{view.foobarProperty}}"),
foobarProperty: Ember.computed(function() {
return 'foobarProperty'; | true |
Other | emberjs | ember.js | c1c720781c976f69fd4014ea50a1fee652286048.json | Change the behavior of Ember.Object.create().
The prior create behavior is available as
Ember.Object.createWithMixins().
We suggest using Ember.Object.extend() to create classes and use create
to initialize properties on your instance.
The new behavior will call computed property setters instead of
overwriting them. This was commonly worked around by calling
setProperties immediately after create.
This improves performance of object creation by 2x. | packages/ember-runtime/lib/system/core_object.js | @@ -24,7 +24,8 @@ var set = Ember.set, get = Ember.get,
applyMixin = Mixin._apply,
finishPartial = Mixin.finishPartial,
reopen = Mixin.prototype.reopen,
- classToString = Mixin.prototype.toString;
+ classToString = Mixin.prototype.toString,
+ MANDATORY_SETTER = Ember.ENV.MANDATORY_SETTER;
var undefinedDescriptor = {
configurable: true,
@@ -39,7 +40,7 @@ function makeCtor() {
// method a lot faster. This is glue code so we want it to be as fast as
// possible.
- var wasApplied = false, initMixins;
+ var wasApplied = false, initMixins, initProperties;
var Class = function() {
if (!wasApplied) {
@@ -50,8 +51,56 @@ function makeCtor() {
var m = meta(this);
m.proto = this;
if (initMixins) {
- this.reopen.apply(this, initMixins);
+ // capture locally so we can clear the closed over variable
+ var mixins = initMixins;
initMixins = null;
+ this.reopen.apply(this, mixins);
+ }
+ if (initProperties) {
+ // capture locally so we can clear the closed over variable
+ var props = initProperties;
+ initProperties = null;
+
+ var concatenatedProperties = this.concatenatedProperties;
+
+ for (var i = 0, l = props.length; i < l; i++) {
+ var properties = props[i];
+ for (var keyName in properties) {
+ if (!properties.hasOwnProperty(keyName)) { continue; }
+
+ var desc = m.descs[keyName],
+ value = properties[keyName];
+
+ Ember.assert("Ember.Object.create no longer supports defining computed properties.", !(value instanceof Ember.ComputedProperty));
+ Ember.assert("Ember.Object.create no longer supports defining bindings.", keyName.substr(-7) !== "Binding");
+
+ if (concatenatedProperties && concatenatedProperties.indexOf(keyName) >= 0) {
+ var baseValue = this[keyName];
+
+ if (baseValue) {
+ if ('function' === typeof baseValue.concat) {
+ value = baseValue.concat(value);
+ } else {
+ value = Ember.makeArray(baseValue).concat(value);
+ }
+ } else {
+ value = Ember.makeArray(value);
+ }
+ }
+
+ if (desc) {
+ desc.set(this, keyName, value);
+ } else {
+ if (typeof this.setUnknownProperty === 'function' && !(keyName in this)) {
+ this.setUnknownProperty(keyName, value);
+ } else if (MANDATORY_SETTER) {
+ Ember.defineProperty(this, keyName, null, value); // setup mandatory setter
+ } else {
+ this[keyName] = value;
+ }
+ }
+ }
+ }
}
finishPartial(this, m);
delete m.proto;
@@ -68,6 +117,7 @@ function makeCtor() {
wasApplied = false;
};
Class._initMixins = function(args) { initMixins = args; };
+ Class._initProperties = function(args) { initProperties = args; };
Class.proto = function() {
var superclass = Class.superclass;
@@ -198,12 +248,18 @@ var ClassMixin = Mixin.create({
return Class;
},
- create: function() {
+ createWithMixins: function() {
var C = this;
if (arguments.length>0) { this._initMixins(arguments); }
return new C();
},
+ create: function() {
+ var C = this;
+ if (arguments.length>0) { this._initProperties(arguments); }
+ return new C();
+ },
+
reopen: function() {
this.willReopen();
reopen.apply(this.PrototypeMixin, arguments); | true |
Other | emberjs | ember.js | c1c720781c976f69fd4014ea50a1fee652286048.json | Change the behavior of Ember.Object.create().
The prior create behavior is available as
Ember.Object.createWithMixins().
We suggest using Ember.Object.extend() to create classes and use create
to initialize properties on your instance.
The new behavior will call computed property setters instead of
overwriting them. This was commonly worked around by calling
setProperties immediately after create.
This improves performance of object creation by 2x. | packages/ember-runtime/tests/legacy_1x/mixins/observable/observable_test.js | @@ -41,7 +41,7 @@ var originalLookup = Ember.lookup, lookup;
module("object.get()", {
setup: function() {
- object = ObservableObject.create(Ember.Observable, {
+ object = ObservableObject.createWithMixins(Ember.Observable, {
normal: 'value',
numberVal: 24,
@@ -90,7 +90,7 @@ test("should call unknownProperty when value is undefined", function() {
//
module("Ember.get()", {
setup: function() {
- objectA = ObservableObject.create({
+ objectA = ObservableObject.createWithMixins({
normal: 'value',
numberVal: 24,
@@ -178,7 +178,7 @@ module("Ember.get() with paths", {
test("should return a property at a given path relative to the lookup", function() {
lookup.Foo = ObservableObject.create({
- Bar: ObservableObject.create({
+ Bar: ObservableObject.createWithMixins({
Baz: Ember.computed(function() { return "blargh"; }).property().volatile()
})
});
@@ -188,7 +188,7 @@ test("should return a property at a given path relative to the lookup", function
test("should return a property at a given path relative to the passed object", function() {
var foo = ObservableObject.create({
- bar: ObservableObject.create({
+ bar: ObservableObject.createWithMixins({
baz: Ember.computed(function() { return "blargh"; }).property().volatile()
})
});
@@ -223,7 +223,7 @@ test("should return a property at a given path relative to the passed object - J
module("object.set()", {
setup: function() {
- object = ObservableObject.create({
+ object = ObservableObject.createWithMixins({
// normal property
normal: 'value',
@@ -313,7 +313,7 @@ module("Computed properties", {
setup: function() {
lookup = Ember.lookup = {};
- object = ObservableObject.create({
+ object = ObservableObject.createWithMixins({
// REGULAR
@@ -527,7 +527,7 @@ test('setting one of two computed properties that depend on a third property sho
});
test("dependent keys should be able to be specified as property paths", function() {
- var depObj = ObservableObject.create({
+ var depObj = ObservableObject.createWithMixins({
menu: ObservableObject.create({
price: 5
}),
@@ -547,7 +547,7 @@ test("dependent keys should be able to be specified as property paths", function
test("nested dependent keys should propagate after they update", function() {
var bindObj;
Ember.run(function () {
- lookup.DepObj = ObservableObject.create({
+ lookup.DepObj = ObservableObject.createWithMixins({
restaurant: ObservableObject.create({
menu: ObservableObject.create({
price: 5
@@ -559,7 +559,7 @@ test("nested dependent keys should propagate after they update", function() {
}).property('restaurant.menu.price').volatile()
});
- bindObj = ObservableObject.create({
+ bindObj = ObservableObject.createWithMixins({
priceBinding: "DepObj.price"
});
});
@@ -587,7 +587,7 @@ test("cacheable nested dependent keys should clear after their dependencies upda
var DepObj;
Ember.run(function(){
- lookup.DepObj = DepObj = ObservableObject.create({
+ lookup.DepObj = DepObj = ObservableObject.createWithMixins({
restaurant: ObservableObject.create({
menu: ObservableObject.create({
price: 5
@@ -640,7 +640,7 @@ test("cacheable nested dependent keys should clear after their dependencies upda
module("Observable objects & object properties ", {
setup: function() {
- object = ObservableObject.create({
+ object = ObservableObject.createWithMixins({
normal: 'value',
abnormal: 'zeroValue', | true |
Other | emberjs | ember.js | c1c720781c976f69fd4014ea50a1fee652286048.json | Change the behavior of Ember.Object.create().
The prior create behavior is available as
Ember.Object.createWithMixins().
We suggest using Ember.Object.extend() to create classes and use create
to initialize properties on your instance.
The new behavior will call computed property setters instead of
overwriting them. This was commonly worked around by calling
setProperties immediately after create.
This improves performance of object creation by 2x. | packages/ember-runtime/tests/legacy_1x/mixins/observable/propertyChanges_test.js | @@ -24,7 +24,7 @@ var revMatches = false , ObjectA;
module("object.propertyChanges", {
setup: function() {
- ObjectA = ObservableObject.create({
+ ObjectA = ObservableObject.createWithMixins({
foo : 'fooValue',
prop : 'propValue',
@@ -115,7 +115,7 @@ test("should notify that the property of an object has changed", function() {
test("should invalidate function property cache when notifyPropertyChange is called", function() {
- var a = ObservableObject.create({
+ var a = ObservableObject.createWithMixins({
_b: null,
b: Ember.computed(function(key, value) {
if (value !== undefined) { | true |
Other | emberjs | ember.js | c1c720781c976f69fd4014ea50a1fee652286048.json | Change the behavior of Ember.Object.create().
The prior create behavior is available as
Ember.Object.createWithMixins().
We suggest using Ember.Object.extend() to create classes and use create
to initialize properties on your instance.
The new behavior will call computed property setters instead of
overwriting them. This was commonly worked around by calling
setProperties immediately after create.
This improves performance of object creation by 2x. | packages/ember-runtime/tests/legacy_1x/system/binding_test.js | @@ -80,7 +80,7 @@ test("deferred observing during bindings", function() {
value2: 'value2'
});
- toObject = Ember.Object.create({
+ toObject = Ember.Object.createWithMixins({
value1: 'value1',
value2: 'value2',
@@ -164,7 +164,7 @@ module("chained binding", {
Ember.run(function() {
first = Ember.Object.create({ output: 'first' }) ;
- second = Ember.Object.create({
+ second = Ember.Object.createWithMixins({
input: 'second',
output: 'second',
@@ -238,7 +238,7 @@ test("two bindings to the same value should sync in the order they are initializ
foo: "bar"
});
- var b = Ember.Object.create({
+ var b = Ember.Object.createWithMixins({
foo: "baz",
fooBinding: "a.foo",
@@ -275,7 +275,7 @@ module("propertyNameBinding with longhand", {
value: "originalValue"
});
- TestNamespace.toObject = Ember.Object.create({
+ TestNamespace.toObject = Ember.Object.createWithMixins({
valueBinding: Ember.Binding.from('TestNamespace.fromObject.value'),
localValue: "originalLocal",
relativeBinding: Ember.Binding.from('localValue') | true |
Other | emberjs | ember.js | c1c720781c976f69fd4014ea50a1fee652286048.json | Change the behavior of Ember.Object.create().
The prior create behavior is available as
Ember.Object.createWithMixins().
We suggest using Ember.Object.extend() to create classes and use create
to initialize properties on your instance.
The new behavior will call computed property setters instead of
overwriting them. This was commonly worked around by calling
setProperties immediately after create.
This improves performance of object creation by 2x. | packages/ember-runtime/tests/legacy_1x/system/object/base_test.js | @@ -80,7 +80,7 @@ module("Ember.Object observers", {
};
// create an object
- obj = Ember.Object.create({
+ obj = Ember.Object.createWithMixins({
prop1: null,
// normal observer | true |
Other | emberjs | ember.js | c1c720781c976f69fd4014ea50a1fee652286048.json | Change the behavior of Ember.Object.create().
The prior create behavior is available as
Ember.Object.createWithMixins().
We suggest using Ember.Object.extend() to create classes and use create
to initialize properties on your instance.
The new behavior will call computed property setters instead of
overwriting them. This was commonly worked around by calling
setProperties immediately after create.
This improves performance of object creation by 2x. | packages/ember-runtime/tests/legacy_1x/system/object/bindings_test.js | @@ -114,7 +114,7 @@ module("fooBinding method", fooBindingModuleOpts);
test("fooBinding: TestNamespace.fromObject.bar should follow absolute path", function() {
// create binding
Ember.run(function(){
- testObject = TestObject.create({
+ testObject = TestObject.createWithMixins({
fooBinding: "TestNamespace.fromObject.bar"
}) ;
@@ -128,7 +128,7 @@ test("fooBinding: TestNamespace.fromObject.bar should follow absolute path", fun
test("fooBinding: .bar should bind to relative path", function() {
Ember.run(function(){
- testObject = TestObject.create({
+ testObject = TestObject.createWithMixins({
fooBinding: "bar"
});
// now make a change to see if the binding triggers.
@@ -140,7 +140,7 @@ test("fooBinding: .bar should bind to relative path", function() {
test('fooBinding: should disconnect bindings when destroyed', function () {
Ember.run(function(){
- testObject = TestObject.create({
+ testObject = TestObject.createWithMixins({
fooBinding: "TestNamespace.fromObject.bar"
});
| true |
Other | emberjs | ember.js | c1c720781c976f69fd4014ea50a1fee652286048.json | Change the behavior of Ember.Object.create().
The prior create behavior is available as
Ember.Object.createWithMixins().
We suggest using Ember.Object.extend() to create classes and use create
to initialize properties on your instance.
The new behavior will call computed property setters instead of
overwriting them. This was commonly worked around by calling
setProperties immediately after create.
This improves performance of object creation by 2x. | packages/ember-runtime/tests/legacy_1x/system/run_loop_test.js | @@ -21,7 +21,7 @@ module("System:run_loop() - chained binding", {
output: 'MyApp.first'
}) ;
- MyApp.second = Ember.Object.create(Ember.Observable, {
+ MyApp.second = Ember.Object.createWithMixins(Ember.Observable, {
input: 'MyApp.second',
output: 'MyApp.second',
| true |
Other | emberjs | ember.js | c1c720781c976f69fd4014ea50a1fee652286048.json | Change the behavior of Ember.Object.create().
The prior create behavior is available as
Ember.Object.createWithMixins().
We suggest using Ember.Object.extend() to create classes and use create
to initialize properties on your instance.
The new behavior will call computed property setters instead of
overwriting them. This was commonly worked around by calling
setProperties immediately after create.
This improves performance of object creation by 2x. | packages/ember-runtime/tests/legacy_1x/system/set_test.js | @@ -41,7 +41,7 @@ test("new Ember.Set([1,2,3]) should create set with three items in them", functi
});
test("new Ember.Set() should accept anything that implements Ember.Array", function() {
- var arrayLikeObject = Ember.Object.create(Ember.Array, {
+ var arrayLikeObject = Ember.Object.createWithMixins(Ember.Array, {
_content: [a,b,c],
length: 3,
objectAt: function(idx) { return this._content[idx]; } | true |
Other | emberjs | ember.js | c1c720781c976f69fd4014ea50a1fee652286048.json | Change the behavior of Ember.Object.create().
The prior create behavior is available as
Ember.Object.createWithMixins().
We suggest using Ember.Object.extend() to create classes and use create
to initialize properties on your instance.
The new behavior will call computed property setters instead of
overwriting them. This was commonly worked around by calling
setProperties immediately after create.
This improves performance of object creation by 2x. | packages/ember-runtime/tests/mixins/array_test.js | @@ -87,7 +87,7 @@ module('mixins/array/arrayContent[Will|Did]Change');
test('should notify observers of []', function() {
- obj = DummyArray.create({
+ obj = DummyArray.createWithMixins({
_count: 0,
enumerablePropertyDidChange: Ember.observer(function() {
this._count++;
@@ -109,7 +109,7 @@ test('should notify observers of []', function() {
module('notify observers of length', {
setup: function() {
- obj = DummyArray.create({
+ obj = DummyArray.createWithMixins({
_after: 0,
lengthDidChange: Ember.observer(function() {
this._after++;
@@ -159,7 +159,7 @@ module('notify array observers', {
setup: function() {
obj = DummyArray.create();
- observer = Ember.Object.create({
+ observer = Ember.Object.createWithMixins({
_before: null,
_after: null,
@@ -224,7 +224,7 @@ module('notify enumerable observers as well', {
setup: function() {
obj = DummyArray.create();
- observer = Ember.Object.create({
+ observer = Ember.Object.createWithMixins({
_before: null,
_after: null,
@@ -367,7 +367,7 @@ test('modifying the array should also indicate the isDone prop itself has change
testBoth("should be clear caches for computed properties that have dependent keys on arrays that are changed after object initialization", function(get, set) {
- var obj = Ember.Object.create({
+ var obj = Ember.Object.createWithMixins({
init: function() {
set(this, 'resources', Ember.A());
},
@@ -387,7 +387,7 @@ testBoth("should be clear caches for computed properties that have dependent key
testBoth("observers that contain @each in the path should fire only once the first time they are accessed", function(get, set) {
var count = 0;
- var obj = Ember.Object.create({
+ var obj = Ember.Object.createWithMixins({
init: function() {
// Observer fires once when resources changes
set(this, 'resources', Ember.A()); | true |
Other | emberjs | ember.js | c1c720781c976f69fd4014ea50a1fee652286048.json | Change the behavior of Ember.Object.create().
The prior create behavior is available as
Ember.Object.createWithMixins().
We suggest using Ember.Object.extend() to create classes and use create
to initialize properties on your instance.
The new behavior will call computed property setters instead of
overwriting them. This was commonly worked around by calling
setProperties immediately after create.
This improves performance of object creation by 2x. | packages/ember-runtime/tests/mixins/deferred_test.js | @@ -5,7 +5,7 @@ test("can resolve deferred", function() {
var deferred, count = 0;
Ember.run(function() {
- deferred = Ember.Object.create(Ember.Deferred);
+ deferred = Ember.Object.createWithMixins(Ember.Deferred);
});
deferred.then(function() {
@@ -28,7 +28,7 @@ test("can reject deferred", function() {
var deferred, count = 0;
Ember.run(function() {
- deferred = Ember.Object.create(Ember.Deferred);
+ deferred = Ember.Object.createWithMixins(Ember.Deferred);
});
deferred.then(function() {}, function() {
@@ -51,7 +51,7 @@ test("can resolve with then", function() {
var deferred, count1 = 0 ,count2 = 0;
Ember.run(function() {
- deferred = Ember.Object.create(Ember.Deferred);
+ deferred = Ember.Object.createWithMixins(Ember.Deferred);
});
deferred.then(function() {
@@ -77,7 +77,7 @@ test("can reject with then", function() {
var deferred, count1 = 0 ,count2 = 0;
Ember.run(function() {
- deferred = Ember.Object.create(Ember.Deferred);
+ deferred = Ember.Object.createWithMixins(Ember.Deferred);
});
deferred.then(function() {
@@ -103,7 +103,7 @@ test("can call resolve multiple times", function() {
var deferred, count = 0;
Ember.run(function() {
- deferred = Ember.Object.create(Ember.Deferred);
+ deferred = Ember.Object.createWithMixins(Ember.Deferred);
});
deferred.then(function() {
@@ -127,7 +127,7 @@ test("resolve prevent reject", function() {
var deferred, resolved = false, rejected = false, progress = 0;
Ember.run(function() {
- deferred = Ember.Object.create(Ember.Deferred);
+ deferred = Ember.Object.createWithMixins(Ember.Deferred);
});
deferred.then(function() {
@@ -155,7 +155,7 @@ test("reject prevent resolve", function() {
var deferred, resolved = false, rejected = false, progress = 0;
Ember.run(function() {
- deferred = Ember.Object.create(Ember.Deferred);
+ deferred = Ember.Object.createWithMixins(Ember.Deferred);
});
deferred.then(function() {
@@ -184,7 +184,7 @@ test("will call callbacks if they are added after resolution", function() {
var deferred, count1 = 0;
Ember.run(function() {
- deferred = Ember.Object.create(Ember.Deferred);
+ deferred = Ember.Object.createWithMixins(Ember.Deferred);
});
stop(); | true |
Other | emberjs | ember.js | c1c720781c976f69fd4014ea50a1fee652286048.json | Change the behavior of Ember.Object.create().
The prior create behavior is available as
Ember.Object.createWithMixins().
We suggest using Ember.Object.extend() to create classes and use create
to initialize properties on your instance.
The new behavior will call computed property setters instead of
overwriting them. This was commonly worked around by calling
setProperties immediately after create.
This improves performance of object creation by 2x. | packages/ember-runtime/tests/mixins/enumerable_test.js | @@ -74,7 +74,7 @@ module('mixins/enumerable/enumerableContentDidChange');
test('should notify observers of []', function() {
- var obj = Ember.Object.create(Ember.Enumerable, {
+ var obj = Ember.Object.createWithMixins(Ember.Enumerable, {
nextObject: function() {}, // avoid exceptions
_count: 0,
@@ -96,7 +96,7 @@ test('should notify observers of []', function() {
module('notify observers of length', {
setup: function() {
- obj = DummyEnum.create({
+ obj = DummyEnum.createWithMixins({
_after: 0,
lengthDidChange: Ember.observer(function() {
this._after++;
@@ -165,7 +165,7 @@ module('notify enumerable observers', {
setup: function() {
obj = DummyEnum.create();
- observer = Ember.Object.create({
+ observer = Ember.Object.createWithMixins({
_before: null,
_after: null,
| true |
Other | emberjs | ember.js | c1c720781c976f69fd4014ea50a1fee652286048.json | Change the behavior of Ember.Object.create().
The prior create behavior is available as
Ember.Object.createWithMixins().
We suggest using Ember.Object.extend() to create classes and use create
to initialize properties on your instance.
The new behavior will call computed property setters instead of
overwriting them. This was commonly worked around by calling
setProperties immediately after create.
This improves performance of object creation by 2x. | packages/ember-runtime/tests/mixins/observable_test.js | @@ -38,7 +38,7 @@ test('should be able to use setProperties to set multiple properties at once', f
testBoth('calling setProperties completes safely despite exceptions', function(get,set) {
var exc = new Error("Something unexpected happened!");
- var obj = Ember.Object.create({
+ var obj = Ember.Object.createWithMixins({
firstName: "Steve",
lastName: "Jobs",
companyName: Ember.computed(function(key, value) {
@@ -69,7 +69,7 @@ testBoth('calling setProperties completes safely despite exceptions', function(g
});
testBoth("should be able to retrieve cached values of computed properties without invoking the computed property", function(get) {
- var obj = Ember.Object.create({
+ var obj = Ember.Object.createWithMixins({
foo: Ember.computed(function() {
return "foo";
}), | true |
Other | emberjs | ember.js | c1c720781c976f69fd4014ea50a1fee652286048.json | Change the behavior of Ember.Object.create().
The prior create behavior is available as
Ember.Object.createWithMixins().
We suggest using Ember.Object.extend() to create classes and use create
to initialize properties on your instance.
The new behavior will call computed property setters instead of
overwriting them. This was commonly worked around by calling
setProperties immediately after create.
This improves performance of object creation by 2x. | packages/ember-runtime/tests/mixins/sortable_test.js | @@ -11,7 +11,7 @@ module("Ember.Sortable with content", {
unsortedArray = Ember.A(Ember.A(array).copy());
- sortedArrayController = Ember.ArrayProxy.create(Ember.SortableMixin, {
+ sortedArrayController = Ember.ArrayProxy.createWithMixins(Ember.SortableMixin, {
content: unsortedArray
});
});
@@ -55,7 +55,7 @@ test("you can change sorted properties", function() {
test("changing sort order triggers observers", function() {
var observer, changeCount = 0;
- observer = Ember.Object.create({
+ observer = Ember.Object.createWithMixins({
array: sortedArrayController,
arrangedDidChange: Ember.observer(function() {
changeCount++;
@@ -149,7 +149,7 @@ test("you can unshift objects in sorted order", function() {
test("addObject does not insert duplicates", function() {
var sortedArrayProxy, obj = {};
- sortedArrayProxy = Ember.ArrayProxy.create(Ember.SortableMixin, {
+ sortedArrayProxy = Ember.ArrayProxy.createWithMixins(Ember.SortableMixin, {
content: Ember.A([obj])
});
| true |
Other | emberjs | ember.js | c1c720781c976f69fd4014ea50a1fee652286048.json | Change the behavior of Ember.Object.create().
The prior create behavior is available as
Ember.Object.createWithMixins().
We suggest using Ember.Object.extend() to create classes and use create
to initialize properties on your instance.
The new behavior will call computed property setters instead of
overwriting them. This was commonly worked around by calling
setProperties immediately after create.
This improves performance of object creation by 2x. | packages/ember-runtime/tests/mixins/target_action_support_test.js | @@ -14,15 +14,15 @@ module("Ember.TargetActionSupport", {
test("it should return false if no target or action are specified", function() {
expect(1);
- var obj = Ember.Object.create(Ember.TargetActionSupport);
+ var obj = Ember.Object.createWithMixins(Ember.TargetActionSupport);
ok(false === obj.triggerAction(), "no target or action was specified");
});
test("it should support actions specified as strings", function() {
expect(2);
- var obj = Ember.Object.create(Ember.TargetActionSupport, {
+ var obj = Ember.Object.createWithMixins(Ember.TargetActionSupport, {
target: Ember.Object.create({
anEvent: function() {
ok(true, "anEvent method was called");
@@ -38,7 +38,7 @@ test("it should support actions specified as strings", function() {
test("it should invoke the send() method on objects that implement it", function() {
expect(2);
- var obj = Ember.Object.create(Ember.TargetActionSupport, {
+ var obj = Ember.Object.createWithMixins(Ember.TargetActionSupport, {
target: Ember.Object.create({
send: function(evt) {
equal(evt, 'anEvent', "send() method was invoked with correct event name");
@@ -63,7 +63,7 @@ test("it should find targets specified using a property path", function() {
}
});
- var myObj = Ember.Object.create(Ember.TargetActionSupport, {
+ var myObj = Ember.Object.createWithMixins(Ember.TargetActionSupport, {
target: 'Test.targetObj',
action: 'anEvent'
}); | true |
Other | emberjs | ember.js | c1c720781c976f69fd4014ea50a1fee652286048.json | Change the behavior of Ember.Object.create().
The prior create behavior is available as
Ember.Object.createWithMixins().
We suggest using Ember.Object.extend() to create classes and use create
to initialize properties on your instance.
The new behavior will call computed property setters instead of
overwriting them. This was commonly worked around by calling
setProperties immediately after create.
This improves performance of object creation by 2x. | packages/ember-runtime/tests/system/array_proxy/content_update_test.js | @@ -10,7 +10,7 @@ test("The `contentArrayDidChange` method is invoked after `content` is updated."
var proxy, observerCalled = false;
- proxy = Ember.ArrayProxy.create({
+ proxy = Ember.ArrayProxy.createWithMixins({
content: Ember.A([]),
arrangedContent: Ember.computed('content', function(key, value) { | true |
Other | emberjs | ember.js | c1c720781c976f69fd4014ea50a1fee652286048.json | Change the behavior of Ember.Object.create().
The prior create behavior is available as
Ember.Object.createWithMixins().
We suggest using Ember.Object.extend() to create classes and use create
to initialize properties on your instance.
The new behavior will call computed property setters instead of
overwriting them. This was commonly worked around by calling
setProperties immediately after create.
This improves performance of object creation by 2x. | packages/ember-runtime/tests/system/object/create_test.js | @@ -2,15 +2,79 @@
module('Ember.Object.create');
+test("simple properties are set", function() {
+ var o = Ember.Object.create({ohai: 'there'});
+ equal(o.get('ohai'), 'there');
+});
+
+test("calls computed property setters", function() {
+ var MyClass = Ember.Object.extend({
+ foo: Ember.computed(function(key, val) {
+ if (arguments.length === 2) { return val; }
+ return "this is not the value you're looking for";
+ })
+ });
+
+ var o = MyClass.create({foo: 'bar'});
+ equal(o.get('foo'), 'bar');
+});
+
+test("sets up mandatory setters for watched simple properties", function() {
+ var MyClass = Ember.Object.extend({
+ foo: null,
+ bar: null,
+ fooDidChange: Ember.observer(function() {}, 'foo')
+ });
+
+ var o = MyClass.create({foo: 'bar', bar: 'baz'});
+ equal(o.get('foo'), 'bar');
+
+ var descriptor = Object.getOwnPropertyDescriptor(o, 'foo');
+ ok(descriptor.set, 'Mandatory setter was setup');
+
+ descriptor = Object.getOwnPropertyDescriptor(o, 'bar');
+ ok(!descriptor.set, 'Mandatory setter was not setup');
+});
+
+test("calls setUnknownProperty if defined", function() {
+ var setUnknownPropertyCalled = false;
+
+ var MyClass = Ember.Object.extend({
+ setUnknownProperty: function(key, value) {
+ setUnknownPropertyCalled = true;
+ }
+ });
+
+ var o = MyClass.create({foo: 'bar'});
+ ok(setUnknownPropertyCalled, 'setUnknownProperty was called');
+});
+
+test("throws if you try to define a computed property", function() {
+ raises(function() {
+ var obj = Ember.Object.create({
+ foo: Ember.computed(function(){})
+ });
+ }, 'should warn that a computed property was passed to create');
+});
+
+test("throws if you try to define a binding", function() {
+ raises(function() {
+ var obj = Ember.Object.create({
+ fooBinding: 'zomg'
+ });
+ }, 'should warn that a binding was passed to create');
+});
+
+module('Ember.Object.createWithMixins');
+
test("Creates a new object that contains passed properties", function() {
var called = false;
- var obj = Ember.Object.create({
+ var obj = Ember.Object.createWithMixins({
prop: 'FOO',
method: function() { called=true; }
});
- //console.log(Ct.dump(obj));
equal(Ember.get(obj, 'prop'), 'FOO', 'obj.prop');
obj.method();
ok(called, 'method executed');
@@ -24,7 +88,7 @@ test("Creates a new object that contains passed properties", function() {
test("Creates a new object that includes mixins and properties", function() {
var MixinA = Ember.Mixin.create({ mixinA: 'A' });
- var obj = Ember.Object.create(MixinA, { prop: 'FOO' });
+ var obj = Ember.Object.createWithMixins(MixinA, { prop: 'FOO' });
equal(Ember.get(obj, 'mixinA'), 'A', 'obj.mixinA');
equal(Ember.get(obj, 'prop'), 'FOO', 'obj.prop');
@@ -37,7 +101,7 @@ test("Creates a new object that includes mixins and properties", function() {
test("Configures _super() on methods with override", function() {
var completed = false;
var MixinA = Ember.Mixin.create({ method: function() {} });
- var obj = Ember.Object.create(MixinA, {
+ var obj = Ember.Object.createWithMixins(MixinA, {
method: function() {
this._super();
completed = true;
@@ -50,7 +114,7 @@ test("Configures _super() on methods with override", function() {
test("Calls init if defined", function() {
var completed = false;
- var obj = Ember.Object.create({
+ var obj = Ember.Object.createWithMixins({
init: function() {
this._super();
completed = true;
@@ -70,7 +134,7 @@ test("Calls all mixin inits if defined", function() {
init: function() { this._super(); completed++; }
});
- Ember.Object.create(Mixin1, Mixin2);
+ Ember.Object.createWithMixins(Mixin1, Mixin2);
equal(completed, 2, 'should have called init for both mixins.');
});
@@ -79,7 +143,7 @@ test('creating an object with required properties', function() {
foo: Ember.required()
});
- var obj = ClassA.create({ foo: 'FOO' }); // should not throw
+ var obj = ClassA.createWithMixins({ foo: 'FOO' }); // should not throw
equal(Ember.get(obj,'foo'), 'FOO');
});
@@ -105,15 +169,15 @@ test('create should not break observed values', function() {
}, 'value')
});
- var obj = CountObject.create({ value: 'foo' });
+ var obj = CountObject.createWithMixins({ value: 'foo' });
equal(obj._count, 0, 'should not fire yet');
Ember.set(obj, 'value', 'BAR');
equal(obj._count, 1, 'should fire');
});
test('bindings on a class should only sync on instances', function() {
- TestObject = Ember.Object.create({
+ TestObject = Ember.Object.createWithMixins({
foo: 'FOO'
});
@@ -124,7 +188,7 @@ test('bindings on a class should only sync on instances', function() {
fooBinding: 'TestObject.foo'
});
- inst = Class.create();
+ inst = Class.createWithMixins();
});
equal(Ember.get(Class.prototype, 'foo'), undefined, 'should not sync binding');
@@ -134,7 +198,7 @@ test('bindings on a class should only sync on instances', function() {
test('inherited bindings should only sync on instances', function() {
- TestObject = Ember.Object.create({
+ TestObject = Ember.Object.createWithMixins({
foo: 'FOO'
});
@@ -148,7 +212,7 @@ test('inherited bindings should only sync on instances', function() {
Ember.run(function() {
Subclass = Class.extend();
- inst = Subclass.create();
+ inst = Subclass.createWithMixins();
});
equal(Ember.get(Class.prototype, 'foo'), undefined, 'should not sync binding on Class');
@@ -168,8 +232,8 @@ test('inherited bindings should only sync on instances', function() {
test("created objects should not share a guid with their superclass", function() {
ok(Ember.guidFor(Ember.Object), "Ember.Object has a guid");
- var objA = Ember.Object.create(),
- objB = Ember.Object.create();
+ var objA = Ember.Object.createWithMixins(),
+ objB = Ember.Object.createWithMixins();
ok(Ember.guidFor(objA) !== Ember.guidFor(objB), "two instances do not share a guid");
}); | true |
Other | emberjs | ember.js | c1c720781c976f69fd4014ea50a1fee652286048.json | Change the behavior of Ember.Object.create().
The prior create behavior is available as
Ember.Object.createWithMixins().
We suggest using Ember.Object.extend() to create classes and use create
to initialize properties on your instance.
The new behavior will call computed property setters instead of
overwriting them. This was commonly worked around by calling
setProperties immediately after create.
This improves performance of object creation by 2x. | packages/ember-runtime/tests/system/object/destroy_test.js | @@ -17,7 +17,7 @@ test("should schedule objects to be destroyed at the end of the run loop", funct
test("should raise an exception when modifying watched properties on a destroyed object", function() {
if (Ember.platform.hasAccessors) {
- var obj = Ember.Object.create({
+ var obj = Ember.Object.createWithMixins({
foo: "bar",
fooDidChange: Ember.observer(function() { }, 'foo')
});
@@ -36,7 +36,7 @@ test("should raise an exception when modifying watched properties on a destroyed
test("observers should not fire after an object has been destroyed", function() {
var count = 0;
- var obj = Ember.Object.create({
+ var obj = Ember.Object.createWithMixins({
fooDidChange: Ember.observer(function() {
count++;
}, 'foo') | true |
Other | emberjs | ember.js | c1c720781c976f69fd4014ea50a1fee652286048.json | Change the behavior of Ember.Object.create().
The prior create behavior is available as
Ember.Object.createWithMixins().
We suggest using Ember.Object.extend() to create classes and use create
to initialize properties on your instance.
The new behavior will call computed property setters instead of
overwriting them. This was commonly worked around by calling
setProperties immediately after create.
This improves performance of object creation by 2x. | packages/ember-runtime/tests/system/object/events_test.js | @@ -4,7 +4,7 @@ test("a listener can be added to an object", function() {
var count = 0;
var F = function() { count++; };
- var obj = Ember.Object.create(Ember.Evented);
+ var obj = Ember.Object.createWithMixins(Ember.Evented);
obj.on('event!', F);
obj.trigger('event!');
@@ -20,7 +20,7 @@ test("a listener can be added and removed automatically the first time it is tri
var count = 0;
var F = function() { count++; };
- var obj = Ember.Object.create(Ember.Evented);
+ var obj = Ember.Object.createWithMixins(Ember.Evented);
obj.one('event!', F);
obj.trigger('event!');
@@ -35,7 +35,7 @@ test("a listener can be added and removed automatically the first time it is tri
test("triggering an event can have arguments", function() {
var self, args;
- var obj = Ember.Object.create(Ember.Evented);
+ var obj = Ember.Object.createWithMixins(Ember.Evented);
obj.on('event!', function() {
args = [].slice.call(arguments);
@@ -51,7 +51,7 @@ test("triggering an event can have arguments", function() {
test("a listener can be added and removed automatically and have arguments", function() {
var self, args, count = 0;
- var obj = Ember.Object.create(Ember.Evented);
+ var obj = Ember.Object.createWithMixins(Ember.Evented);
obj.one('event!', function() {
args = [].slice.call(arguments);
@@ -75,7 +75,7 @@ test("a listener can be added and removed automatically and have arguments", fun
test("binding an event can specify a different target", function() {
var self, args;
- var obj = Ember.Object.create(Ember.Evented);
+ var obj = Ember.Object.createWithMixins(Ember.Evented);
var target = {};
obj.on('event!', target, function() {
@@ -94,7 +94,7 @@ test("a listener registered with one can take method as string and can be added
var target = {};
target.fn = function() { count++; };
- var obj = Ember.Object.create(Ember.Evented);
+ var obj = Ember.Object.createWithMixins(Ember.Evented);
obj.one('event!', target, 'fn');
obj.trigger('event!');
@@ -107,7 +107,7 @@ test("a listener registered with one can take method as string and can be added
});
test("a listener registered with one can be removed with off", function() {
- var obj = Ember.Object.create(Ember.Evented, {
+ var obj = Ember.Object.createWithMixins(Ember.Evented, {
F: function() {}
});
var F = function() {}; | true |
Other | emberjs | ember.js | c1c720781c976f69fd4014ea50a1fee652286048.json | Change the behavior of Ember.Object.create().
The prior create behavior is available as
Ember.Object.createWithMixins().
We suggest using Ember.Object.extend() to create classes and use create
to initialize properties on your instance.
The new behavior will call computed property setters instead of
overwriting them. This was commonly worked around by calling
setProperties immediately after create.
This improves performance of object creation by 2x. | packages/ember-runtime/tests/system/object/extend_test.js | @@ -42,7 +42,7 @@ test('Overriding a method several layers deep', function() {
equal(obj.barCnt, 2, 'should invoke both');
// Try overriding on create also
- obj = FinalClass.create({
+ obj = FinalClass.createWithMixins({
foo: function() { this.fooCnt++; this._super(); }
});
| true |
Other | emberjs | ember.js | c1c720781c976f69fd4014ea50a1fee652286048.json | Change the behavior of Ember.Object.create().
The prior create behavior is available as
Ember.Object.createWithMixins().
We suggest using Ember.Object.extend() to create classes and use create
to initialize properties on your instance.
The new behavior will call computed property setters instead of
overwriting them. This was commonly worked around by calling
setProperties immediately after create.
This improves performance of object creation by 2x. | packages/ember-runtime/tests/system/object/observer_test.js | @@ -55,7 +55,7 @@ testBoth('observer on subclass', function(get, set) {
testBoth('observer on instance', function(get, set) {
- var obj = Ember.Object.create({
+ var obj = Ember.Object.createWithMixins({
count: 0,
@@ -84,7 +84,7 @@ testBoth('observer on instance overridding class', function(get, set) {
});
- var obj = MyClass.create({
+ var obj = MyClass.createWithMixins({
foo: Ember.observer(function() {
set(this, 'count', get(this, 'count')+1);
}, 'baz') // <-- change property we observe
@@ -102,7 +102,7 @@ testBoth('observer on instance overridding class', function(get, set) {
testBoth('observer should not fire after being destroyed', function(get, set) {
- var obj = Ember.Object.create({
+ var obj = Ember.Object.createWithMixins({
count: 0,
foo: Ember.observer(function() {
set(this, 'count', get(this, 'count')+1);
@@ -169,11 +169,11 @@ testBoth('chain observer on class', function(get, set) {
}, 'bar.baz')
});
- var obj1 = MyClass.create({
+ var obj1 = MyClass.createWithMixins({
bar: { baz: 'biff' }
});
- var obj2 = MyClass.create({
+ var obj2 = MyClass.createWithMixins({
bar: { baz: 'biff2' },
bar2: { baz: 'biff3' },
| true |
Other | emberjs | ember.js | c1c720781c976f69fd4014ea50a1fee652286048.json | Change the behavior of Ember.Object.create().
The prior create behavior is available as
Ember.Object.createWithMixins().
We suggest using Ember.Object.extend() to create classes and use create
to initialize properties on your instance.
The new behavior will call computed property setters instead of
overwriting them. This was commonly worked around by calling
setProperties immediately after create.
This improves performance of object creation by 2x. | packages/ember-views/lib/views/view.js | @@ -2159,7 +2159,7 @@ Ember.View = Ember.CoreView.extend(
attrs._parentView = this;
attrs.templateData = attrs.templateData || get(this, 'templateData');
- view = view.create(attrs);
+ view = view.createWithMixins(attrs);
// don't set the property on a virtual view, as they are invisible to
// consumers of the view API | true |
Other | emberjs | ember.js | c1c720781c976f69fd4014ea50a1fee652286048.json | Change the behavior of Ember.Object.create().
The prior create behavior is available as
Ember.Object.createWithMixins().
We suggest using Ember.Object.extend() to create classes and use create
to initialize properties on your instance.
The new behavior will call computed property setters instead of
overwriting them. This was commonly worked around by calling
setProperties immediately after create.
This improves performance of object creation by 2x. | packages/ember-views/tests/system/event_dispatcher_test.js | @@ -24,7 +24,7 @@ test("should dispatch events to views", function() {
var childKeyDownCalled = 0;
var parentKeyDownCalled = 0;
- view = Ember.ContainerView.create({
+ view = Ember.ContainerView.createWithMixins({
childViews: ['child'],
child: Ember.View.extend({
@@ -80,7 +80,7 @@ test("should dispatch events to views", function() {
test("should not dispatch events to views not inDOM", function() {
var receivedEvent;
- view = Ember.View.create({
+ view = Ember.View.createWithMixins({
render: function(buffer) {
buffer.push('some <span id="awesome">awesome</span> content');
this._super(buffer);
@@ -220,7 +220,7 @@ test("should dispatch events to nearest event manager", function() {
test("event manager should be able to re-dispatch events to view", function() {
var receivedEvent=0;
- view = Ember.ContainerView.create({
+ view = Ember.ContainerView.createWithMixins({
elementId: 'containerView',
eventManager: Ember.Object.create({ | true |
Other | emberjs | ember.js | c1c720781c976f69fd4014ea50a1fee652286048.json | Change the behavior of Ember.Object.create().
The prior create behavior is available as
Ember.Object.createWithMixins().
We suggest using Ember.Object.extend() to create classes and use create
to initialize properties on your instance.
The new behavior will call computed property setters instead of
overwriting them. This was commonly worked around by calling
setProperties immediately after create.
This improves performance of object creation by 2x. | packages/ember-views/tests/system/jquery_ext_test.js | @@ -53,7 +53,7 @@ test("drop handler should receive event with dataTransfer property", function()
var receivedEvent;
var dropCalled = 0;
- view = Ember.View.create({
+ view = Ember.View.createWithMixins({
render: function(buffer) {
buffer.push('please drop stuff on me');
this._super(buffer); | true |
Other | emberjs | ember.js | c1c720781c976f69fd4014ea50a1fee652286048.json | Change the behavior of Ember.Object.create().
The prior create behavior is available as
Ember.Object.createWithMixins().
We suggest using Ember.Object.extend() to create classes and use create
to initialize properties on your instance.
The new behavior will call computed property setters instead of
overwriting them. This was commonly worked around by calling
setProperties immediately after create.
This improves performance of object creation by 2x. | packages/ember-views/tests/views/container_view_test.js | @@ -34,7 +34,7 @@ test("should be able to observe properties that contain child views", function()
var container;
Ember.run(function() {
- container = Ember.ContainerView.create({
+ container = Ember.ContainerView.createWithMixins({
childViews: ['displayView'],
displayIsDisplayedBinding: 'displayView.isDisplayed',
@@ -99,7 +99,7 @@ test("should set the parentView property on views that are added to the child vi
test("views that are removed from a ContainerView should have their child views cleared", function() {
var container = Ember.ContainerView.create();
- var view = Ember.View.create({
+ var view = Ember.View.createWithMixins({
remove: function() {
this._super();
}, | true |
Other | emberjs | ember.js | c1c720781c976f69fd4014ea50a1fee652286048.json | Change the behavior of Ember.Object.create().
The prior create behavior is available as
Ember.Object.createWithMixins().
We suggest using Ember.Object.extend() to create classes and use create
to initialize properties on your instance.
The new behavior will call computed property setters instead of
overwriting them. This was commonly worked around by calling
setProperties immediately after create.
This improves performance of object creation by 2x. | packages/ember-views/tests/views/view/init_test.js | @@ -28,9 +28,11 @@ test("registers itself with a controller if the viewController property is set",
equal(lookup.TestApp.fooController.get('view'), v, "sets the view property of the controller");
});
+module("Ember.View.createWithMixins");
+
test("should warn if a non-array is used for classNames", function() {
raises(function() {
- Ember.View.create({
+ Ember.View.createWithMixins({
classNames: Ember.computed(function() {
return ['className'];
}).property().volatile()
@@ -40,7 +42,7 @@ test("should warn if a non-array is used for classNames", function() {
test("should warn if a non-array is used for classNamesBindings", function() {
raises(function() {
- Ember.View.create({
+ Ember.View.createWithMixins({
classNameBindings: Ember.computed(function() {
return ['className'];
}).property().volatile() | true |
Other | emberjs | ember.js | c1c720781c976f69fd4014ea50a1fee652286048.json | Change the behavior of Ember.Object.create().
The prior create behavior is available as
Ember.Object.createWithMixins().
We suggest using Ember.Object.extend() to create classes and use create
to initialize properties on your instance.
The new behavior will call computed property setters instead of
overwriting them. This was commonly worked around by calling
setProperties immediately after create.
This improves performance of object creation by 2x. | packages/ember-views/tests/views/view/render_test.js | @@ -10,15 +10,15 @@ module("Ember.View#render");
test("default implementation does not render child views", function() {
var rendered = 0, updated = 0, parentRendered = 0, parentUpdated = 0 ;
- var view = Ember.ContainerView.create({
+ var view = Ember.ContainerView.createWithMixins({
childViews: ["child"],
render: function(buffer) {
parentRendered++;
this._super(buffer);
},
- child: Ember.View.create({
+ child: Ember.View.createWithMixins({
render: function(buffer) {
rendered++;
this._super(buffer);
@@ -38,15 +38,15 @@ test("default implementation does not render child views", function() {
test("should invoke renderChildViews if layer is destroyed then re-rendered", function() {
var rendered = 0, parentRendered = 0, parentUpdated = 0 ;
- var view = Ember.ContainerView.create({
+ var view = Ember.ContainerView.createWithMixins({
childViews: ["child"],
render: function(buffer) {
parentRendered++;
this._super(buffer);
},
- child: Ember.View.create({
+ child: Ember.View.createWithMixins({
render: function(buffer) {
rendered++;
this._super(buffer); | true |
Other | emberjs | ember.js | c1c720781c976f69fd4014ea50a1fee652286048.json | Change the behavior of Ember.Object.create().
The prior create behavior is available as
Ember.Object.createWithMixins().
We suggest using Ember.Object.extend() to create classes and use create
to initialize properties on your instance.
The new behavior will call computed property setters instead of
overwriting them. This was commonly worked around by calling
setProperties immediately after create.
This improves performance of object creation by 2x. | packages/ember-views/tests/views/view/view_lifecycle_test.js | @@ -33,7 +33,7 @@ test("should create and append a DOM element after bindings have synced", functi
fakeThing: 'controllerPropertyValue'
});
- view = Ember.View.create({
+ view = Ember.View.createWithMixins({
fooBinding: 'ViewTest.fakeController.fakeThing',
render: function(buffer) { | true |
Other | emberjs | ember.js | 635de93a9329f3f3fbf53473542b266805f81cc6.json | Use Ember.$ in the tests | packages/ember-views/tests/system/render_buffer_test.js | @@ -179,6 +179,6 @@ test("properly handles old IE's zero-scope bug", function() {
buffer.push('<script></script>foo');
var element = buffer.element();
- ok($(element).html().match(/script/i), "should have script tag");
- ok(!$(element).html().match(/­/), "should not have ­");
+ ok(Ember.$(element).html().match(/script/i), "should have script tag");
+ ok(!Ember.$(element).html().match(/­/), "should not have ­");
}); | false |
Other | emberjs | ember.js | 16b3af3762bcf3b430c677de3eebff25236f3cac.json | Use createElement and innerHTML | packages/ember-views/lib/system/render_buffer.js | @@ -348,14 +348,44 @@ Ember._RenderBuffer.prototype =
of this buffer
*/
element: function() {
- return Ember.$(this.string())[0];
+ var element = document.createElement(this.elementTag),
+ id = this.elementId,
+ classes = this.elementClasses,
+ attrs = this.elementAttributes,
+ style = this.elementStyle,
+ styleBuffer = '', prop;
+
+ if (id) { element.setAttribute('id', id); }
+ if (classes) { element.setAttribute('class', classes.toDOM()); }
+
+ if (style) {
+ for (prop in style) {
+ if (style.hasOwnProperty(prop)) {
+ styleBuffer += (prop + ':' + style[prop] + ';');
+ }
+ }
+
+ element.setAttribute('style', styleBuffer);
+ }
+
+ if (attrs) {
+ for (prop in attrs) {
+ if (attrs.hasOwnProperty(prop)) {
+ element.setAttribute(prop, attrs[prop]);
+ }
+ }
+ }
+
+ this.elementTag = ''; // hack to avoid creating an innerString function
+ element.innerHTML = this.string();
+ return element;
},
/**
Generates the HTML content for this buffer.
@method string
- @return {String} The generated HTMl
+ @return {String} The generated HTML
*/
string: function() {
var content = []; | false |
Other | emberjs | ember.js | 37107a04e46852086077f428d99f91e7d59926fb.json | Implement a default computed property setter.
If your computed property's function is defined with two arguments we
assume you've implemented a setter. If you do not implement a setter, we will
overwrite the computed property with the value you've set. | packages/ember-metal/lib/computed.js | @@ -314,8 +314,11 @@ ComputedPropertyPrototype.set = function(obj, keyName, value) {
// argument.
if (func.length === 3) {
ret = func.call(obj, keyName, value, cachedValue);
- } else {
+ } else if (func.length === 2) {
ret = func.call(obj, keyName, value);
+ } else {
+ Ember.defineProperty(obj, keyName, null, value);
+ return;
}
if (hadCachedValue && cachedValue === ret) { return; } | true |
Other | emberjs | ember.js | 37107a04e46852086077f428d99f91e7d59926fb.json | Implement a default computed property setter.
If your computed property's function is defined with two arguments we
assume you've implemented a setter. If you do not implement a setter, we will
overwrite the computed property with the value you've set. | packages/ember-metal/tests/computed_test.js | @@ -178,7 +178,7 @@ module('Ember.computed - cacheable', {
setup: function() {
obj = {};
count = 0;
- Ember.defineProperty(obj, 'foo', Ember.computed(function() {
+ Ember.defineProperty(obj, 'foo', Ember.computed(function(key, value) {
count++;
return 'bar '+count;
}));
@@ -290,7 +290,7 @@ module('Ember.computed - dependentkey', {
setup: function() {
obj = { bar: 'baz' };
count = 0;
- Ember.defineProperty(obj, 'foo', Ember.computed(function() {
+ Ember.defineProperty(obj, 'foo', Ember.computed(function(key, value) {
count++;
return 'bar '+count;
}).property('bar'));
@@ -357,12 +357,12 @@ testBoth('should invalidate multiple nested dependent keys', function(get, set)
testBoth('circular keys should not blow up', function(get, set) {
- Ember.defineProperty(obj, 'bar', Ember.computed(function() {
+ Ember.defineProperty(obj, 'bar', Ember.computed(function(key, value) {
count++;
return 'bar '+count;
}).property('foo'));
- Ember.defineProperty(obj, 'foo', Ember.computed(function() {
+ Ember.defineProperty(obj, 'foo', Ember.computed(function(key, value) {
count++;
return 'foo '+count;
}).property('bar'));
@@ -656,6 +656,21 @@ testBoth('setting a cached computed property that modifies the value you give it
equal(plusOneDidChange, 2);
});
+module('Ember.computed - default setter');
+
+testBoth("when setting a value on a computed property that doesn't handle sets", function(get, set) {
+ var obj = {};
+
+ Ember.defineProperty(obj, 'foo', Ember.computed(function() {
+ return 'foo';
+ }));
+
+ Ember.set(obj, 'foo', 'bar');
+
+ equal(Ember.get(obj, 'foo'), 'bar', 'The set value is properly returned');
+ ok(!Ember.meta(obj).descs.foo, 'The computed property was removed');
+});
+
module('CP macros');
testBoth('Ember.computed.not', function(get, set) { | true |
Other | emberjs | ember.js | 27cca3ff3d67bcd9972d3d7f4480c084b7acf843.json | Add support for {{action}} and events | .jshintrc | @@ -15,6 +15,7 @@
"requireModule",
"equal",
"test",
+ "asyncTest",
"testBoth",
"testWithDefault",
"raises", | true |
Other | emberjs | ember.js | 27cca3ff3d67bcd9972d3d7f4480c084b7acf843.json | Add support for {{action}} and events | packages/ember-handlebars/lib/helpers/action.js | @@ -44,7 +44,7 @@ ActionHelper.registerAction = function(actionName, options) {
var target = options.target;
// Check for StateManager (or compatible object)
- if (target.isState && typeof target.send === 'function') {
+ if (typeof target.send === 'function') {
return target.send(actionName, event);
} else {
Ember.assert(Ember.String.fmt('Target %@ does not have action %@', [target, actionName]), target[actionName]); | true |
Other | emberjs | ember.js | 27cca3ff3d67bcd9972d3d7f4480c084b7acf843.json | Add support for {{action}} and events | packages/ember-routing/lib/system/route.js | @@ -49,8 +49,10 @@ Ember.Route = Ember.Object.extend({
return modelClass.find(value);
},
- setupControllers: function(context) {
-
+ setupControllers: function(controller, context) {
+ if (controller) {
+ controller.set('content', context);
+ }
},
controller: function(name) {
@@ -77,6 +79,8 @@ Ember.Route = Ember.Object.extend({
controller = this.lookup('controller', controller);
}
+ controller = controller || this.context;
+
set(view, 'controller', controller);
var parentView = this.lookup('view', into); | true |
Other | emberjs | ember.js | 27cca3ff3d67bcd9972d3d7f4480c084b7acf843.json | Add support for {{action}} and events | packages/ember-routing/lib/system/router.js | @@ -26,6 +26,14 @@ Ember.Router = Ember.Object.extend({
transitionTo: function(handler) {
var args = [].slice.call(arguments);
this.router.transitionTo.apply(this.router, args);
+ },
+
+ send: function(name, context) {
+ if (Ember.$ && context instanceof Ember.$.Event) {
+ context = context.context;
+ }
+
+ this.router.trigger(name, context);
}
});
| true |
Other | emberjs | ember.js | 27cca3ff3d67bcd9972d3d7f4480c084b7acf843.json | Add support for {{action}} and events | packages/ember-routing/lib/vendor/router.js | @@ -116,8 +116,8 @@ define("router",
this.updateURL(url);
},
- trigger: function(name) {
- trigger(this, name);
+ trigger: function(name, context) {
+ trigger(this, name, context);
}
};
@@ -406,7 +406,7 @@ define("router",
return handlers;
}
- function trigger(router, name) {
+ function trigger(router, name, context) {
var currentHandlerInfos = router.currentHandlerInfos;
if (!currentHandlerInfos) {
@@ -418,7 +418,7 @@ define("router",
handler = handlerInfo.handler;
if (handler.events && handler.events[name]) {
- handler.events[name](handler);
+ handler.events[name](handler, context);
break;
}
} | true |
Other | emberjs | ember.js | 27cca3ff3d67bcd9972d3d7f4480c084b7acf843.json | Add support for {{action}} and events | packages/ember-routing/tests/integration/basic_test.js | @@ -137,7 +137,7 @@ test("The Homepage with a `setupControllers` hook modifying other controllers",
equal(Ember.$('ul li', '#qunit-fixture').eq(2).text(), "Sunday: Noon to 6pm", "The template was rendered with the hours context");
});
-test("The Homepage getting its controller context via controllerContext", function() {
+test("The Homepage getting its controller context via model", function() {
Router.map(function(match) {
match("/").to("home");
});
@@ -440,4 +440,88 @@ test("Nested callbacks are not exited when moving to siblings", function() {
deepEqual(urls, ['/specials/1']);
});
+asyncTest("Events are triggered on the current state", function() {
+ Router.map(function(match) {
+ match("/").to("home");
+ });
+
+ var model = { name: "Tom Dale" };
+
+ App.HomeRoute = Ember.Route.extend({
+ model: function() {
+ return model;
+ },
+
+ events: {
+ showStuff: function(handler, obj) {
+ ok(handler instanceof App.HomeRoute, "the handler is an App.HomeRoute");
+ deepEqual(obj, { name: "Tom Dale" }, "the context is correct");
+ start();
+ }
+ }
+ });
+
+ Ember.TEMPLATES.home = Ember.Handlebars.compile(
+ "<a {{action showStuff content}}>{{name}}</a>"
+ );
+
+ bootApplication();
+
+ var controller = router._container.controller.home = Ember.Controller.create();
+ controller.target = router;
+
+ Ember.run(function() {
+ router.handleURL("/");
+ });
+
+ var actionId = Ember.$("#qunit-fixture a").data("ember-action");
+ var action = Ember.Handlebars.ActionHelper.registeredActions[actionId];
+ var event = new Ember.$.Event("click");
+ action.handler(event);
+});
+
+asyncTest("Events are triggered on the current state", function() {
+ Router.map(function(match) {
+ match("/").to("root", function(match) {
+ match("/").to("home");
+ });
+ });
+
+ var model = { name: "Tom Dale" };
+
+ App.RootRoute = Ember.Route.extend({
+ events: {
+ showStuff: function(handler, obj) {
+ ok(handler instanceof App.RootRoute, "the handler is an App.HomeRoute");
+ deepEqual(obj, { name: "Tom Dale" }, "the context is correct");
+ start();
+ }
+ }
+ });
+
+ App.HomeRoute = Ember.Route.extend({
+ model: function() {
+ return model;
+ }
+ });
+
+ Ember.TEMPLATES.home = Ember.Handlebars.compile(
+ "<a {{action showStuff content}}>{{name}}</a>"
+ );
+
+ bootApplication();
+
+ var controller = router._container.controller.home = Ember.Controller.create();
+ controller.target = router;
+
+ Ember.run(function() {
+ router.handleURL("/");
+ });
+
+ var actionId = Ember.$("#qunit-fixture a").data("ember-action");
+ var action = Ember.Handlebars.ActionHelper.registeredActions[actionId];
+ var event = new Ember.$.Event("click");
+ action.handler(event);
+});
+
// TODO: Parent context change | true |
Other | emberjs | ember.js | 3634605361d7dca709838583de051b9a91e6d4d3.json | Implement basic serialize | packages/ember-routing/lib/system/route.js | @@ -20,6 +20,15 @@ Ember.Route = Ember.Object.extend({
return this.model(params);
},
+ serialize: function(model, params) {
+ if (params.length !== 1) { return; }
+
+ var name = params[0], object = {};
+ object[name] = get(model, 'id');
+
+ return object;
+ },
+
model: function(params) {
var match, name, value;
| true |
Other | emberjs | ember.js | 3634605361d7dca709838583de051b9a91e6d4d3.json | Implement basic serialize | packages/ember-routing/lib/system/router.js | @@ -16,10 +16,16 @@ Ember.Router = Ember.Object.extend({
router.map(this.constructor.callback);
router.getHandler = getHandlerFunction(this, container);
+ router.updateURL = this.updateURL;
},
handleURL: function(url) {
this.router.handleURL(url);
+ },
+
+ transitionTo: function(handler) {
+ var args = [].slice.call(arguments);
+ this.router.transitionTo.apply(this.router, args);
}
});
| true |
Other | emberjs | ember.js | 3634605361d7dca709838583de051b9a91e6d4d3.json | Implement basic serialize | packages/ember-routing/lib/vendor/router.js | @@ -103,7 +103,7 @@ define("router",
if (names.length) {
object = objects.shift();
- if (handler.serialize) { merge(params, handler.serialize(object)); }
+ if (handler.serialize) { merge(params, handler.serialize(object, names)); }
} else {
object = handler.deserialize && handler.deserialize({});
} | true |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.