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 | 4331b5365034565ae1fadffb0a824c9e4967a00d.json | Add layout support to Ember.View | packages/ember-views/tests/views/view/layout_test.js | @@ -0,0 +1,95 @@
+var set = Ember.set, get = Ember.get;
+
+module("Ember.View - Template Functionality");
+
+test("should call the function of the associated layout", function() {
+ var view;
+ var templateCalled = 0, layoutCalled = 0;
+
+ view = Ember.View.create({
+ layoutName: 'layout',
+ templateName: 'template',
+
+ templates: {
+ template: function() {
+ templateCalled++;
+ },
+
+ layout: function() {
+ layoutCalled++;
+ }
+ }
+ });
+
+ view.createElement();
+
+ equal(templateCalled, 0, "template is not called when layout is present");
+ equal(layoutCalled, 1, "layout is called when layout is present");
+});
+
+test("should call the function of the associated template with itself as the context", function() {
+ var view;
+
+ view = Ember.View.create({
+ layoutName: 'test_template',
+
+ personName: "Tom DAAAALE",
+
+ templates: Ember.Object.create({
+ test_template: function(dataSource) {
+ return "<h1 id='twas-called'>template was called for " + get(dataSource, 'personName') + "</h1>";
+ }
+ })
+ });
+
+ view.createElement();
+
+ equal("template was called for Tom DAAAALE", view.$('#twas-called').text(), "the named template was called with the view as the data source");
+});
+
+test("should fall back to defaultTemplate if neither template nor templateName are provided", function() {
+ var View, view;
+
+ View = Ember.View.extend({
+ defaultLayout: function(dataSource) { return "<h1 id='twas-called'>template was called for " + get(dataSource, 'personName') + "</h1>"; }
+ });
+
+ view = View.create({
+ personName: "Tom DAAAALE"
+ });
+
+ view.createElement();
+
+ equal("template was called for Tom DAAAALE", view.$('#twas-called').text(), "the named template was called with the view as the data source");
+});
+
+test("should not use defaultLayout if layout is provided", function() {
+ var View, view;
+
+ View = Ember.View.extend({
+ layout: function() { return "foo"; },
+ defaultLayout: function(dataSource) { return "<h1 id='twas-called'>template was called for " + get(dataSource, 'personName') + "</h1>"; }
+ });
+
+ view = View.create();
+ view.createElement();
+
+ equal("foo", view.$().text(), "default layout was not printed");
+});
+
+test("the template property is available to the layout template", function() {
+ var view = Ember.View.create({
+ template: function(context, options) {
+ options.data.buffer.push(" derp");
+ },
+
+ layout: function(context, options) {
+ options.data.buffer.push("Herp");
+ get(context, 'template')(context, options);
+ }
+ });
+
+ view.createElement();
+
+ equal("Herp derp", view.$().text(), "the layout has access to the template");
+}); | true |
Other | emberjs | ember.js | 6661f147e764f5275e4301ca5f4dadea1893a283.json | Ignore more parent properties | packages/ember-metal/lib/mixin.js | @@ -413,7 +413,7 @@ function findNamespaces() {
// globalStorage is a storage obsoleted by the WhatWG storage specification. See https://developer.mozilla.org/en/DOM/Storage#globalStorage
if (prop === "globalStorage" && window.StorageList && window.globalStorage instanceof window.StorageList) { continue; }
// Don't access properties on parent window, which will throw "Access/Permission Denied" in IE/Firefox for windows on different domains
- if (prop === "parent") { continue; }
+ if (prop === "parent" || prop === "top" || prop === "frameElement" || prop === "content") { continue; }
// Unfortunately, some versions of IE don't support window.hasOwnProperty
if (window.hasOwnProperty && !window.hasOwnProperty(prop)) { continue; }
| false |
Other | emberjs | ember.js | dff8edefdf0c25aa206719cbca85934596936432.json | fix incorrect message in equals test | packages/ember-runtime/tests/suites/enumerable/contains.js | @@ -19,6 +19,6 @@ suite.test('contains returns true if items is in enumerable', function() {
suite.test('contains returns false if item is not in enumerable', function() {
var data = this.newFixture(1);
var obj = this.newObject(this.newFixture(3));
- equals(obj.contains(data[0]), false, 'should return true if not contained');
+ equals(obj.contains(data[0]), false, 'should return false if not contained');
});
| false |
Other | emberjs | ember.js | 4c3107d23844580eb81147c84af3a8fc21c48664.json | Fix path resolution for states
The name property of states was busted. We now
have two properties--name and path--that describe
the individual name of the state, as well as the
path to it from the root. | packages/ember-states/lib/state.js | @@ -1,12 +1,24 @@
-var get = Ember.get, set = Ember.set;
+var get = Ember.get, set = Ember.set, getPath = Ember.getPath;
Ember.State = Ember.Object.extend({
isState: true,
parentState: null,
start: null,
+ name: null,
+ path: Ember.computed(function() {
+ var parentPath = getPath(this, 'parentState.path'),
+ path = get(this, 'name');
+
+ if (parentPath) {
+ path = parentPath + '.' + path;
+ }
+
+ return path;
+ }).property().cacheable(),
init: function() {
var states = get(this, 'states'), foundStates;
+ var name;
// As a convenience, loop over the properties
// of this state and look for any that are other
@@ -17,14 +29,14 @@ Ember.State = Ember.Object.extend({
if (!states) {
states = {};
- for (var name in this) {
+ for (name in this) {
if (name === "constructor") { continue; }
this.setupChild(states, name, this[name]);
}
set(this, 'states', states);
} else {
- for (var name in states) {
+ for (name in states) {
this.setupChild(states, name, states[name]);
}
}
@@ -36,12 +48,15 @@ Ember.State = Ember.Object.extend({
if (!value) { return false; }
if (Ember.State.detect(value)) {
- value = value.create();
+ value = value.create({
+ name: name
+ });
+ } else if (value.isState) {
+ set(value, 'name', name);
}
if (value.isState) {
set(value, 'parentState', this);
- set(value, 'name', (get(this, 'name') || '') + '.' + name);
states[name] = value;
}
}, | true |
Other | emberjs | ember.js | 4c3107d23844580eb81147c84af3a8fc21c48664.json | Fix path resolution for states
The name property of states was busted. We now
have two properties--name and path--that describe
the individual name of the state, as well as the
path to it from the root. | packages/ember-states/lib/state_manager.js | @@ -80,7 +80,7 @@ Ember.StateManager = Ember.State.extend(
if (parentState) {
this.sendRecursively(event, parentState, context);
} else if (get(this, 'errorOnUnhandledEvent')) {
- throw new Ember.Error(this.toString() + " could not respond to event " + event + ".");
+ throw new Ember.Error(this.toString() + " could not respond to event " + event + " in state " + getPath(this, 'currentState.name') + ".");
}
}
}, | true |
Other | emberjs | ember.js | 4c3107d23844580eb81147c84af3a8fc21c48664.json | Fix path resolution for states
The name property of states was busted. We now
have two properties--name and path--that describe
the individual name of the state, as well as the
path to it from the root. | packages/ember-states/tests/state_test.js | @@ -86,3 +86,39 @@ test("a state finds properties that are state classes and instantiates them", fu
equal(get(states.state1, 'isState1'), true, "instantiated first state");
equal(get(states.state2, 'isState2'), true, "instantiated second state");
});
+
+test("states set up proper names on their children", function() {
+ var manager = Ember.StateManager.create({
+ states: {
+ first: Ember.State.extend({
+ insideFirst: Ember.State.extend({
+
+ })
+ })
+ }
+ });
+
+ manager.goToState('first');
+ equal(getPath(manager, 'currentState.path'), 'first');
+
+ manager.goToState('first.insideFirst');
+ equal(getPath(manager, 'currentState.path'), 'first.insideFirst');
+});
+
+test("states with child instances set up proper names on their children", function() {
+ var manager = Ember.StateManager.create({
+ states: {
+ first: Ember.State.create({
+ insideFirst: Ember.State.create({
+
+ })
+ })
+ }
+ });
+
+ manager.goToState('first');
+ equal(getPath(manager, 'currentState.path'), 'first');
+
+ manager.goToState('first.insideFirst');
+ equal(getPath(manager, 'currentState.path'), 'first.insideFirst');
+}); | true |
Other | emberjs | ember.js | c93627fe2a6f136ab83bd36292d917d6c09432bc.json | Add pointer to website repository | docs/README.md | @@ -1,5 +1,6 @@
-Ember Documentation
-========================
+# Ember Documentation
+
+## Building the Documentation
Generating the Ember documentation requires node.js, as well as the port of jsdoc-toolkit to node, located [here](https://github.com/p120ph37/node-jsdoc-toolkit). In order to build the docs, run the following commands from the `docs` directory:
@@ -21,4 +22,9 @@ Using that, running ./run won't fail with latest node.js installed.
./run
If you wish to consult it without installing node.js and the toolkit a static version is provided [here](https://s3.amazonaws.com/emberjs/emberjs-docs-as-of-2012-01-04.zip).
-Please note that it will not be as up to date as building it yourself but it is provided as a convenience for the time being.
\ No newline at end of file
+Please note that it will not be as up to date as building it yourself but it is provided as a convenience for the time being.
+
+## Contributing to the Website
+
+The repository for the [emberjs.com](http://emberjs.com/) website is located at
+<a href="https://github.com/emberjs/website">github.com/emberjs/website</a>. | false |
Other | emberjs | ember.js | 8c87d67414b338d3c7e979fd06f0357b9ec32684.json | Fix typo in Ember.MutableEnumerable#addObjects | packages/ember-runtime/lib/mixins/mutable_enumerable.js | @@ -69,7 +69,7 @@ Ember.MutableEnumerable = Ember.Mixin.create(Ember.Enumerable,
/**
Adds each object in the passed enumerable to the receiver.
- @param {Ember.Enumerable} objects the objects to remove
+ @param {Ember.Enumerable} objects the objects to add.
@returns {Object} receiver
*/
addObjects: function(objects) { | false |
Other | emberjs | ember.js | f272b70b774f179899f72dd958557acba9bb24e3.json | Ignore docs folder | .gitignore | @@ -15,9 +15,7 @@ assets/bpm_styles.css
bin/
coverage
dist
-doc/
-docs/jsdoc
-docs/output
+docs
lib/*/tests/all.js
lib/*/tests/qunit*
lib/bundler/man | false |
Other | emberjs | ember.js | f9375ca87191d93edfc4f9726d2ec353c98a2a7d.json | Use Ember.$ instead of $ global | packages/ember-handlebars/lib/helpers/action.js | @@ -9,7 +9,7 @@ ActionHelper.registerAction = function(actionName, eventName, target, view) {
existingHandler = view[eventName];
function handler(event) {
- if ($(event.target).closest('[data-ember-action]').attr('data-ember-action') === actionId) {
+ if (Ember.$(event.target).closest('[data-ember-action]').attr('data-ember-action') === actionId) {
if ('function' === typeof target.send) {
return target.send(actionName);
} else { | false |
Other | emberjs | ember.js | ea26cf46fdfb1f5308530d8c9570e7ff2b78a4c2.json | Remove more trailing commas. | packages/ember-metal/tests/mixin/observer_test.js | @@ -122,7 +122,7 @@ testBoth('observing chain with property in mixin applied later', function(get, s
count: 0,
foo: Ember.observer(function() {
set(this, 'count', get(this, 'count')+1);
- }, 'bar.baz'),
+ }, 'bar.baz')
});
var MyMixin2 = Ember.Mixin.create({bar: obj2});
@@ -144,7 +144,7 @@ testBoth('observing chain with existing property', function(get, set) {
count: 0,
foo: Ember.observer(function() {
set(this, 'count', get(this, 'count')+1);
- }, 'bar.baz'),
+ }, 'bar.baz')
});
var obj = Ember.mixin({bar: obj2}, MyMixin);
@@ -162,7 +162,7 @@ testBoth('observing chain with property in mixin before', function(get, set) {
count: 0,
foo: Ember.observer(function() {
set(this, 'count', get(this, 'count')+1);
- }, 'bar.baz'),
+ }, 'bar.baz')
});
var obj = Ember.mixin({}, MyMixin2, MyMixin);
@@ -180,7 +180,7 @@ testBoth('observing chain with property in mixin after', function(get, set) {
count: 0,
foo: Ember.observer(function() {
set(this, 'count', get(this, 'count')+1);
- }, 'bar.baz'),
+ }, 'bar.baz')
});
var obj = Ember.mixin({}, MyMixin, MyMixin2);
@@ -200,7 +200,7 @@ testBoth('observing chain with overriden property', function(get, set) {
count: 0,
foo: Ember.observer(function() {
set(this, 'count', get(this, 'count')+1);
- }, 'bar.baz'),
+ }, 'bar.baz')
});
var obj = Ember.mixin({bar: obj2}, MyMixin, MyMixin2); | false |
Other | emberjs | ember.js | d34ab243b9c9a5ca26f89b36b2e90da2f88108da.json | Remove trailing comma | packages/ember-views/tests/views/view/attribute_bindings_test.js | @@ -21,7 +21,7 @@ test("should render attribute bindings", function() {
exists: true,
nothing: null,
notDefined: undefined,
- notNumber: NaN,
+ notNumber: NaN
});
view.createElement(); | false |
Other | emberjs | ember.js | 8061b909c33024b93ec163882be3ec7dad921495.json | Add Ember.Select control | packages/ember-handlebars/lib/controls.js | @@ -10,3 +10,4 @@ require("ember-handlebars/controls/button");
require("ember-handlebars/controls/radio_button");
require("ember-handlebars/controls/text_area");
require("ember-handlebars/controls/tabs");
+require("ember-handlebars/controls/select"); | true |
Other | emberjs | ember.js | 8061b909c33024b93ec163882be3ec7dad921495.json | Add Ember.Select control | packages/ember-handlebars/lib/controls/select.js | @@ -0,0 +1,68 @@
+var set = Ember.set, get = Ember.get, getPath = Ember.getPath;
+
+Ember.Select = Ember.CollectionView.extend({
+ tagName: 'select',
+
+ optionLabelPath: 'content',
+ optionValuePath: 'content',
+
+ selection: null,
+
+ didInsertElement: function() {
+ var selection = get(this, 'selection');
+
+ if (selection) { this.selectionDidChange(); }
+
+ this.change();
+ },
+
+ change: function() {
+ var selectedIndex = this.$()[0].selectedIndex,
+ content = get(this, 'content');
+
+ if (!content) { return; }
+
+ set(this, 'selection', content.objectAt(selectedIndex));
+ },
+
+ selectionDidChange: Ember.observer(function() {
+ var el = this.$()[0],
+ content = get(this, 'content'),
+ selection = get(this, 'selection'),
+ selectionIndex = content.indexOf(selection);
+
+ if (el) { el.selectedIndex = selectionIndex; }
+ }, 'selection'),
+
+ itemViewClass: Ember.View.extend({
+ template: Ember.Handlebars.compile("{{label}}"),
+ attributeBindings: ['value'],
+
+ init: function() {
+ this.labelPathDidChange();
+ this.valuePathDidChange();
+
+ this._super();
+ },
+
+ labelPathDidChange: Ember.observer(function() {
+ var labelPath = getPath(this, 'parentView.optionLabelPath');
+
+ if (!labelPath) { return; }
+
+ Ember.defineProperty(this, 'label', Ember.computed(function() {
+ return getPath(this, labelPath);
+ }).property(labelPath).cacheable());
+ }, 'parentView.optionLabelPath'),
+
+ valuePathDidChange: Ember.observer(function() {
+ var valuePath = getPath(this, 'parentView.optionValuePath');
+
+ if (!valuePath) { return; }
+
+ Ember.defineProperty(this, 'value', Ember.computed(function() {
+ return getPath(this, valuePath);
+ }).property(valuePath).cacheable());
+ }, 'parentView.optionValuePath')
+ })
+}); | true |
Other | emberjs | ember.js | 8061b909c33024b93ec163882be3ec7dad921495.json | Add Ember.Select control | packages/ember-handlebars/tests/controls/select_test.js | @@ -0,0 +1,81 @@
+var application, select;
+
+module("Ember.Select", {
+ setup: function() {
+ application = Ember.Application.create();
+ select = Ember.Select.create();
+ },
+
+ teardown: function() {
+ select.destroy();
+ application.destroy();
+ }
+});
+
+function append() {
+ Ember.run(function() {
+ select.appendTo('#qunit-fixture');
+ });
+}
+
+test("should render", function() {
+ append();
+
+ ok(select.$().length, "Select renders");
+});
+
+test("can have options", function() {
+ select.set('content', Ember.A([1, 2, 3]));
+
+ append();
+
+ equals(select.$('option').length, 3, "Should have three options");
+ equals(select.$().text(), "123", "Options should have content");
+});
+
+test("can specify the property path for an option's label and value", function() {
+ select.set('content', Ember.A([
+ { id: 1, firstName: 'Yehuda' },
+ { id: 2, firstName: 'Tom' }
+ ]));
+
+ select.set('optionLabelPath', 'content.firstName');
+ select.set('optionValuePath', 'content.id');
+
+ append();
+
+ equals(select.$('option').length, 2, "Should have two options");
+ equals(select.$().text(), "YehudaTom", "Options should have content");
+ deepEqual(select.$('option').toArray().map(function(el) { return $(el).attr('value'); }), ["1", "2"], "Options should have values");
+});
+
+test("can retrieve the current selected option", function() {
+ var yehuda = { id: 1, firstName: 'Yehuda' },
+ tom = { id: 2, firstName: 'Tom' };
+ select.set('content', Ember.A([yehuda, tom]));
+
+ append();
+
+ equals(select.get('selection'), yehuda, "By default, the first option is selected");
+
+ select.$()[0].selectedIndex = 1; // select Tom
+ select.$().trigger('change');
+
+ equals(select.get('selection'), tom, "On change, the new option should be selected");
+});
+
+test("selection can be set", function() {
+ var yehuda = { id: 1, firstName: 'Yehuda' },
+ tom = { id: 2, firstName: 'Tom' };
+ select.set('content', Ember.A([yehuda, tom]));
+
+ select.set('selection', tom);
+
+ append();
+
+ equals(select.get('selection'), tom, "Initial selection should be correct");
+
+ select.set('selection', yehuda);
+
+ equals(select.$()[0].selectedIndex, 0, "After changing it, selection should be correct");
+}); | true |
Other | emberjs | ember.js | 60c55e3085b5c36569328be4414faa0383c5e3ba.json | Add Ember.Handlebars action helper | packages/ember-handlebars/lib/helpers.js | @@ -11,3 +11,4 @@ require("ember-handlebars/helpers/unbound");
require("ember-handlebars/helpers/debug");
require("ember-handlebars/helpers/each");
require("ember-handlebars/helpers/template");
+require("ember-handlebars/helpers/action");
\ No newline at end of file | true |
Other | emberjs | ember.js | 60c55e3085b5c36569328be4414faa0383c5e3ba.json | Add Ember.Handlebars action helper | packages/ember-handlebars/lib/helpers/action.js | @@ -0,0 +1,54 @@
+require('ember-handlebars/ext');
+
+var EmberHandlebars = Ember.Handlebars, getPath = Ember.Handlebars.getPath;
+
+var ActionHelper = EmberHandlebars.ActionHelper = {};
+
+ActionHelper.registerAction = function(actionName, eventName, target, view) {
+ var actionId = (++jQuery.uuid).toString(),
+ existingHandler = view[eventName],
+ originalRerender = view.rerender,
+ handler;
+
+ if (existingHandler) {
+ var handler = function(event) {
+ if ($(event.target).closest('[data-ember-action]').attr('data-ember-action') === actionId) {
+ return target[actionName](event);
+ } else if (existingHandler) {
+ return existingHandler.call(view, event);
+ }
+ };
+ } else {
+ var handler = function(event) {
+ if ($(event.target).closest('[data-ember-action]').attr('data-ember-action') === actionId) {
+ return target[actionName](event);
+ }
+ };
+ }
+
+ view[eventName] = handler;
+
+ view.rerender = function() {
+ if (existingHandler) {
+ view[eventName] = existingHandler;
+ } else {
+ view[eventName] = null;
+ }
+ originalRerender.call(this);
+ };
+
+ return actionId;
+};
+
+EmberHandlebars.registerHelper('action', function(actionName, options) {
+ var hash = options.hash || {},
+ eventName = options.hash.on || "click",
+ view = options.data.view,
+ target;
+
+ if (view.isVirtual) { view = view.get('parentView'); }
+ target = options.hash.target ? getPath(this, options.hash.target) : view;
+
+ var actionId = ActionHelper.registerAction(actionName, eventName, target, view);
+ return new EmberHandlebars.SafeString('data-ember-action="' + actionId + '"');
+}); | true |
Other | emberjs | ember.js | 60c55e3085b5c36569328be4414faa0383c5e3ba.json | Add Ember.Handlebars action helper | packages/ember-handlebars/tests/helpers/action_test.js | @@ -0,0 +1,252 @@
+var application, view,
+ ActionHelper = Ember.Handlebars.ActionHelper,
+ originalRegisterAction = ActionHelper.registerAction;
+
+var appendView = function() {
+ Ember.run(function() { view.appendTo('#qunit-fixture'); });
+};
+
+module("Ember.Handlebars - action helper", {
+ setup: function() {
+ application = Ember.Application.create();
+ },
+
+ teardown: function() {
+ Ember.run(function() {
+ view.destroy();
+ application.destroy();
+ });
+ }
+});
+
+test("should output a data attribute with a guid", function() {
+ view = Ember.View.create({
+ template: Ember.Handlebars.compile('<a href="#" {{action "edit"}}>')
+ });
+
+ appendView();
+
+ ok(view.$('a').attr('data-ember-action').match(/\d+/), "A data-ember-action attribute with a guid was added");
+});
+
+test("should by default register a click event", function() {
+ var registeredEventName;
+
+ ActionHelper.registerAction = function(_, eventName) {
+ registeredEventName = eventName;
+ };
+
+ view = Ember.View.create({
+ template: Ember.Handlebars.compile('<a href="#" {{action "edit"}}>')
+ });
+
+ appendView();
+
+ equals(registeredEventName, 'click', "The click event was properly registered");
+
+ ActionHelper.registerAction = originalRegisterAction;
+});
+
+test("should allow alternative events to be handled", function() {
+ var registeredEventName;
+
+ ActionHelper.registerAction = function(_, eventName) {
+ registeredEventName = eventName;
+ };
+
+ view = Ember.View.create({
+ template: Ember.Handlebars.compile('<a href="#" {{action "edit" on="mouseUp"}}>')
+ });
+
+ appendView();
+
+ equals(registeredEventName, 'mouseUp', "The alternative mouseUp event was properly registered");
+
+ ActionHelper.registerAction = originalRegisterAction;
+});
+
+test("should by default target the parent view", function() {
+ var registeredTarget;
+
+ ActionHelper.registerAction = function(_, _, target) {
+ registeredTarget = target;
+ };
+
+ view = Ember.View.create({
+ template: Ember.Handlebars.compile('<a href="#" {{action "edit"}}>')
+ });
+
+ appendView();
+
+ equals(registeredTarget, view, "The parent view was registered as the target");
+
+ ActionHelper.registerAction = originalRegisterAction;
+});
+
+test("should allow a target to be specified", function() {
+ var registeredTarget;
+
+ ActionHelper.registerAction = function(_, _, target) {
+ registeredTarget = target;
+ };
+
+ var anotherTarget = Ember.View.create();
+
+ view = Ember.View.create({
+ template: Ember.Handlebars.compile('<a href="#" {{action "edit" target="anotherTarget"}}>'),
+ anotherTarget: anotherTarget
+ });
+
+ appendView();
+
+ equals(registeredTarget, anotherTarget, "The specified target was registered");
+
+ ActionHelper.registerAction = originalRegisterAction;
+});
+
+test("should attach an event handler on the parent view", function() {
+ var eventHandlerWasCalled = false;
+
+ view = Ember.View.create({
+ template: Ember.Handlebars.compile('<a href="#" {{action "edit"}}>click me</a>'),
+ edit: function() { eventHandlerWasCalled = true; }
+ });
+
+ appendView();
+
+ ok('function' === typeof view.click, "An event handler was added to the parent view");
+
+ view.$('a').trigger('click');
+
+ ok(eventHandlerWasCalled, "The event handler was called");
+});
+
+test("should wrap an existing event handler on the parent view", function() {
+ var eventHandlerWasCalled = false,
+ originalEventHandlerWasCalled = false;
+
+ view = Ember.View.create({
+ template: Ember.Handlebars.compile('<a href="#" {{action "edit"}}>click me</a>'),
+ click: function() { originalEventHandlerWasCalled = true; },
+ edit: function() { eventHandlerWasCalled = true; }
+ });
+
+ appendView();
+
+ view.$('a').trigger('click');
+
+ ok(eventHandlerWasCalled, "The event handler was called");
+ ok(!originalEventHandlerWasCalled, "The parent view's event handler wasn't called");
+
+ eventHandlerWasCalled = originalEventHandlerWasCalled = false;
+
+ view.$().trigger('click');
+
+ ok(!eventHandlerWasCalled, "The event handler wasn't called");
+ ok(originalEventHandlerWasCalled, "The parent view's event handler was called");
+});
+
+test("should be able to use action more than once for the same event within a view", function() {
+ var editWasCalled = false,
+ deleteWasCalled = false,
+ originalEventHandlerWasCalled = false;
+
+ view = Ember.View.create({
+ template: Ember.Handlebars.compile(
+ '<a id="edit" href="#" {{action "edit"}}>edit</a><a id="delete" href="#" {{action "delete"}}>delete</a>'
+ ),
+ click: function() { originalEventHandlerWasCalled = true; },
+ edit: function() { editWasCalled = true; },
+ delete: function() { deleteWasCalled = true; }
+ });
+
+ appendView();
+
+ view.$('#edit').trigger('click');
+
+ ok(editWasCalled && !deleteWasCalled && !originalEventHandlerWasCalled, "Only the edit action was called");
+
+ editWasCalled = deleteWasCalled = originalEventHandlerWasCalled = false;
+
+ view.$('#delete').trigger('click');
+
+ ok(!editWasCalled && deleteWasCalled && !originalEventHandlerWasCalled, "Only the delete action was called");
+
+ editWasCalled = deleteWasCalled = originalEventHandlerWasCalled = false;
+
+ view.$().trigger('click');
+
+ ok(!editWasCalled && !deleteWasCalled && originalEventHandlerWasCalled, "Only the original event handler was called");
+});
+
+test("should work properly in an #each block", function() {
+ var eventHandlerWasCalled = false;
+
+ view = Ember.View.create({
+ items: Ember.A([1, 2, 3, 4]),
+ template: Ember.Handlebars.compile('{{#each items}}<a href="#" {{action "edit"}}>click me</a>{{/each}}'),
+ edit: function() { eventHandlerWasCalled = true; }
+ });
+
+ appendView();
+
+ ok('function' === typeof view.click, "The event handler was added to the parent view");
+
+ view.$('a').trigger('click');
+
+ ok(eventHandlerWasCalled, "The event handler was called");
+});
+
+test("should work properly in a #with block", function() {
+ var eventHandlerWasCalled = false;
+
+ view = Ember.View.create({
+ something: {ohai: 'there'},
+ template: Ember.Handlebars.compile('{{#with something}}<a href="#" {{action "edit"}}>click me</a>{{/with}}'),
+ edit: function() { eventHandlerWasCalled = true; }
+ });
+
+ appendView();
+
+ ok('function' === typeof view.click, "The event handler was added to the parent view");
+
+ view.$('a').trigger('click');
+
+ ok(eventHandlerWasCalled, "The event handler was called");
+});
+
+test("should unwrap parent view event handlers on rerender", function() {
+ var eventHandlerWasCalled = false;
+
+ view = Ember.View.create({
+ template: Ember.Handlebars.compile('<a href="#" {{action "edit"}}>click me</a>'),
+ edit: function() { eventHandlerWasCalled = true; }
+ });
+
+ appendView();
+
+ ok('function' === typeof view.click, "The event handler was added to the parent view");
+
+ view.rerender();
+
+ ok(view.click === null, "On rerender, the event handler was removed");
+
+ Ember.run.end();
+
+ ok('function' === typeof view.click, "After rerender completes, a new event handler was added");
+});
+
+test("should properly capture events on child elements of a container with an action", function() {
+ var eventHandlerWasCalled = false;
+
+ view = Ember.View.create({
+ template: Ember.Handlebars.compile('<div {{action "edit"}}><button>click me</button></div>'),
+ edit: function() { eventHandlerWasCalled = true; }
+ });
+
+ appendView();
+
+ view.$('button').trigger('click');
+
+ ok(eventHandlerWasCalled, "Event on a child element triggered the action of it's parent")
+}); | true |
Other | emberjs | ember.js | 949f380718e796bf4441694fea4b564349f9204d.json | Add a runtime target for node usage. | Rakefile | @@ -74,7 +74,8 @@ task :metamorph => compile_package_task("metamorph")
task :build => ["ember:metal", "ember:runtime", "ember:handlebars", "ember:views", "ember:states", "ember:datetime", :handlebars, :metamorph]
distributions = {
- "ember" => ["handlebars", "ember-metal", "ember-runtime", "ember-views", "ember-states", "metamorph", "ember-handlebars"]
+ "ember" => ["handlebars", "ember-metal", "ember-runtime", "ember-views", "ember-states", "metamorph", "ember-handlebars"],
+ "ember-runtime" => ["ember-metal", "ember-runtime"]
}
distributions.each do |name, libraries| | false |
Other | emberjs | ember.js | cd4b0b2c14c99c1c78e87c9014d4686b2b8d39af.json | Fix template in Ember.RadioButton. | packages/ember-handlebars/lib/controls/radio_button.js | @@ -17,7 +17,7 @@ Ember.RadioButton = Ember.View.extend({
classNames: ['ember-radio-button'],
- defaultTemplate: Ember.Handlebars.compile('<input type="radio" {{bindAttr disabled="disabled" name="group" value="val" checked="checked"}}>{{title}}</input>'),
+ defaultTemplate: Ember.Handlebars.compile('<label><input type="radio" {{bindAttr disabled="disabled" name="group" value="val" checked="checked"}}>{{title}}</label>'),
change: function() {
Ember.run.once(this, this._updateElementValue); | false |
Other | emberjs | ember.js | ffef82e6d94faa3e10133c7cca32e0f5698ca811.json | add image of current travis ci build status | README.md | @@ -1,4 +1,4 @@
-# Ember.js
+# Ember.js [](http://travis-ci.org/emberjs/ember.js)
Ember.js (formerly SproutCore 2.0) is a JavaScript framework that does all of the heavy lifting that you'd normally have to do by hand. There are tasks that are common to every web app; Ember.js does those things for you, so you can focus on building killer features and UI.
| false |
Other | emberjs | ember.js | 3d1094139785cc4dcb50a259f39c10852cc59537.json | add upload task | Gemfile | @@ -6,3 +6,4 @@ gem "execjs", "~> 1.2.6"
gem "rack"
gem "rake-pipeline", :git => "https://github.com/livingsocial/rake-pipeline.git"
gem "rake-pipeline-web-filters", :git => "https://github.com/wycats/rake-pipeline-web-filters.git"
+gem "github-upload"
\ No newline at end of file | true |
Other | emberjs | ember.js | 3d1094139785cc4dcb50a259f39c10852cc59537.json | add upload task | Gemfile.lock | @@ -22,9 +22,24 @@ GIT
GEM
remote: http://rubygems.org/
specs:
+ confparser (0.0.2.1)
execjs (1.2.6)
multi_json (~> 1.0)
+ faster_xml_simple (0.5.0)
+ libxml-ruby (>= 0.3.8.4)
+ github-upload (0.0.2)
+ confparser
+ net-github-upload (>= 0.0.6)
+ httpclient (2.2.4)
+ json (1.6.3)
+ libxml-ruby (2.2.2)
multi_json (1.0.3)
+ net-github-upload (0.0.7)
+ faster_xml_simple
+ httpclient
+ json
+ nokogiri (>= 1.4.0)
+ nokogiri (1.5.0)
rack (1.3.5)
rake (0.9.2.2)
thor (0.14.6)
@@ -37,6 +52,7 @@ PLATFORMS
DEPENDENCIES
execjs (~> 1.2.6)
+ github-upload
rack
rake-pipeline!
rake-pipeline-web-filters! | true |
Other | emberjs | ember.js | 3d1094139785cc4dcb50a259f39c10852cc59537.json | add upload task | Rakefile | @@ -1,5 +1,8 @@
abort "Please use Ruby 1.9 to build Ember.js!" if RUBY_VERSION !~ /^1\.9/
+require "rubygems"
+require "net/github-upload"
+
require "bundler/setup"
require "erb"
require "uglifier"
@@ -124,6 +127,48 @@ end
+### UPLOAD LATEST EMBERJS BUILD TASK ###
+desc "Upload latest Ember.js build to GitHub repository"
+task :upload => [:clean, :dist] do
+ # setup
+ login = `git config github.user`.chomp # your login for github
+ token = `git config github.token`.chomp # your token for github
+
+ # get repo from git config's origin url
+ origin = `git config remote.origin.url`.chomp # url to origin
+ # extract USERNAME/REPO_NAME
+ # sample urls: https://github.com/emberjs/ember.js.git
+ # git://github.com/emberjs/ember.js.git
+ r = /github\.com\S*[\/:](\w+\/[\w\.]+)\.\w*/
+ repo = r.match(origin).captures.first
+ puts "Uploading to repository: " + repo
+
+ gh = Net::GitHub::Upload.new(
+ :login => login,
+ :token => token
+ )
+
+ puts "Uploading ember-latest.js"
+ gh.replace(
+ :repos => repo,
+ :file => 'dist/ember.js',
+ :name => 'ember-latest.js',
+ :content_type => 'application/json',
+ :description => "latest build of ember.js"
+ )
+
+ puts "Uploading ember-latest.min.js"
+ gh.replace(
+ :repos => repo,
+ :file => 'dist/ember.min.js',
+ :name => 'ember-latest.min.js',
+ :content_type => 'application/json',
+ :description => "latest minified build of ember.js"
+ )
+end
+
+
+
### RELEASE TASKS ###
EMBER_VERSION = File.read("VERSION").strip | true |
Other | emberjs | ember.js | 68ded658b1baa1801effd2094ac526b014609372.json | Move states property to Ember.State
Easy access to substates for everyone, not just StateManagers | packages/ember-states/lib/state.js | @@ -6,14 +6,27 @@ Ember.State = Ember.Object.extend({
start: null,
init: function() {
- Ember.keys(this).forEach(function(name) {
- var value = this[name];
-
- if (value && value.isState) {
- set(value, 'parentState', this);
- set(value, 'name', (get(this, 'name') || '') + '.' + name);
- }
- }, this);
+ var states = get(this, 'states');
+
+ if (!states) {
+ states = {};
+ Ember.keys(this).forEach(function(name) {
+ if (this.hasOwnProperty(name)) {
+ var value = this[name];
+
+ if (value && value.isState) {
+ set(value, 'parentState', this);
+ set(value, 'name', (get(this, 'name') || '') + '.' + name);
+
+ states[name] = value;
+ }
+ }
+ }, this);
+
+ if (Ember.keys(states).length > 0) { set(this, 'states', states); }
+ }
+
+ set(this, 'routes', {});
},
enter: Ember.K, | true |
Other | emberjs | ember.js | 68ded658b1baa1801effd2094ac526b014609372.json | Move states property to Ember.State
Easy access to substates for everyone, not just StateManagers | packages/ember-states/lib/state_manager.js | @@ -18,20 +18,6 @@ Ember.StateManager = Ember.State.extend(
init: function() {
this._super();
- var states = get(this, 'states');
- if (!states) {
- states = {};
- Ember.keys(this).forEach(function(name) {
- var value = get(this, name);
-
- if (value && value.isState) {
- states[name] = value;
- }
- }, this);
-
- set(this, 'states', states);
- }
-
var initialState = get(this, 'initialState');
if (!initialState && get(this, 'start')) { | true |
Other | emberjs | ember.js | 5bafc9c5126fdeedff94ccaa834e126322cdb0c3.json | Update Array#lastIndexOf documentation | packages/ember-runtime/lib/mixins/array.js | @@ -140,7 +140,7 @@ Ember.Array = Ember.Mixin.create(Ember.Enumerable, /** @scope Ember.Array.protot
@returns {Number} index or -1 if not found
@example
- arr = ["a", "b", "c", "d", "a"];
+ var arr = ["a", "b", "c", "d", "a"];
arr.indexOf("a"); => 0
arr.indexOf("z"); => -1
arr.indexOf("a", 2); => 4
@@ -161,11 +161,23 @@ Ember.Array = Ember.Mixin.create(Ember.Enumerable, /** @scope Ember.Array.protot
},
/**
- Returns the last index for a particular object in the index.
+ Returns the index of the given object's last occurrence.
+ If no startAt argument is given, the starting location to
+ search is 0. If it's negative, will count backward from
+ the end of the array. Returns -1 if no match is found.
@param {Object} object the item to search for
- @param {NUmber} startAt optional starting location to search, default 0
- @returns {Number} index of -1 if not found
+ @param {Number} startAt optional starting location to search, default 0
+ @returns {Number} index or -1 if not found
+
+ @example
+ var arr = ["a", "b", "c", "d", "a"];
+ arr.lastIndexOf("a"); => 4
+ arr.lastIndexOf("z"); => -1
+ arr.lastIndexOf("a", 2); => 0
+ arr.lastIndexOf("a", -1); => 4
+ arr.lastIndexOf("b", 3); => 1
+ arr.lastIndexOf("a", 100); => 4
*/
lastIndexOf: function(object, startAt) {
var idx, len = get(this, 'length'); | false |
Other | emberjs | ember.js | 96522474290fd46353045b1655febf349843fba2.json | Fix doc typo. | packages/ember-handlebars/lib/helpers/binding.js | @@ -16,7 +16,7 @@ var helpers = EmberHandlebars.helpers;
(function() {
// Binds a property into the DOM. This will create a hook in DOM that the
- // KVO system will look for and upate if the property changes.
+ // KVO system will look for and update if the property changes.
var bind = function(property, options, preserveContext, shouldDisplay) {
var data = options.data,
fn = options.fn, | false |
Other | emberjs | ember.js | 44af4f35fb85651dc84b3c24e763bcb26eae79d4.json | Add bin/ to gitignore | .gitignore | @@ -12,6 +12,7 @@ _yardoc
assets
assets/bpm_libs.js
assets/bpm_styles.css
+bin/
coverage
dist
doc/ | false |
Other | emberjs | ember.js | c5f2eeaafe09026bceda4b90981836eed6a607e6.json | Save shared data structures to local variables | packages/ember-handlebars/lib/helpers/binding.js | @@ -11,6 +11,9 @@ require('ember-handlebars/views/metamorph_view');
var get = Ember.get, getPath = Ember.getPath, set = Ember.set, fmt = Ember.String.fmt;
+var EmberHandlebars = Ember.Handlebars, helpers = EmberHandlebars.helpers;
+var helpers = EmberHandlebars.helpers;
+
(function() {
// Binds a property into the DOM. This will create a hook in DOM that the
// KVO system will look for and upate if the property changes.
@@ -64,28 +67,28 @@ var get = Ember.get, getPath = Ember.getPath, set = Ember.set, fmt = Ember.Strin
data.buffer.push(getPath(this, property));
}
};
-
+
/**
'_triageMustache' is used internally select between a binding and helper for
the given context. Until this point, it would be hard to determine if the
mustache is a property reference or a regular helper reference. This triage
helper resolves that.
-
+
This would not be typically invoked by directly.
-
+
@private
@name Handlebars.helpers._triageMustache
@param {String} property Property/helperID to triage
@param {Function} fn Context to provide for rendering
@returns {String} HTML string
*/
- Ember.Handlebars.registerHelper('_triageMustache', function(property, fn) {
+ EmberHandlebars.registerHelper('_triageMustache', function(property, fn) {
ember_assert("You cannot pass more than one argument to the _triageMustache helper", arguments.length <= 2);
- if (Ember.Handlebars.helpers[property]) {
- return Ember.Handlebars.helpers[property].call(this, fn);
+ if (helpers[property]) {
+ return helpers[property].call(this, fn);
}
else {
- return Ember.Handlebars.helpers.bind.apply(this, arguments);
+ return helpers.bind.apply(this, arguments);
}
});
@@ -109,7 +112,7 @@ var get = Ember.get, getPath = Ember.getPath, set = Ember.set, fmt = Ember.Strin
@param {Function} fn Context to provide for rendering
@returns {String} HTML string
*/
- Ember.Handlebars.registerHelper('bind', function(property, fn) {
+ EmberHandlebars.registerHelper('bind', function(property, fn) {
ember_assert("You cannot pass more than one argument to the bind helper", arguments.length <= 2);
var context = (fn.contexts && fn.contexts[0]) || this;
@@ -133,7 +136,7 @@ var get = Ember.get, getPath = Ember.getPath, set = Ember.set, fmt = Ember.Strin
@param {Function} fn Context to provide for rendering
@returns {String} HTML string
*/
- Ember.Handlebars.registerHelper('boundIf', function(property, fn) {
+ EmberHandlebars.registerHelper('boundIf', function(property, fn) {
var context = (fn.contexts && fn.contexts[0]) || this;
return bind.call(context, property, fn, true, function(result) {
@@ -152,11 +155,11 @@ var get = Ember.get, getPath = Ember.getPath, set = Ember.set, fmt = Ember.Strin
@param {Hash} options
@returns {String} HTML string
*/
-Ember.Handlebars.registerHelper('with', function(context, options) {
+EmberHandlebars.registerHelper('with', function(context, options) {
ember_assert("You must pass exactly one argument to the with helper", arguments.length == 2);
ember_assert("You must pass a block to the with helper", options.fn && options.fn !== Handlebars.VM.noop);
- return Ember.Handlebars.helpers.bind.call(options.contexts[0], context, options);
+ return helpers.bind.call(options.contexts[0], context, options);
});
@@ -166,11 +169,11 @@ Ember.Handlebars.registerHelper('with', function(context, options) {
@param {Hash} options
@returns {String} HTML string
*/
-Ember.Handlebars.registerHelper('if', function(context, options) {
+EmberHandlebars.registerHelper('if', function(context, options) {
ember_assert("You must pass exactly one argument to the if helper", arguments.length == 2);
ember_assert("You must pass a block to the if helper", options.fn && options.fn !== Handlebars.VM.noop);
- return Ember.Handlebars.helpers.boundIf.call(options.contexts[0], context, options);
+ return helpers.boundIf.call(options.contexts[0], context, options);
});
/**
@@ -179,7 +182,7 @@ Ember.Handlebars.registerHelper('if', function(context, options) {
@param {Hash} options
@returns {String} HTML string
*/
-Ember.Handlebars.registerHelper('unless', function(context, options) {
+EmberHandlebars.registerHelper('unless', function(context, options) {
ember_assert("You must pass exactly one argument to the unless helper", arguments.length == 2);
ember_assert("You must pass a block to the unless helper", options.fn && options.fn !== Handlebars.VM.noop);
@@ -188,7 +191,7 @@ Ember.Handlebars.registerHelper('unless', function(context, options) {
options.fn = inverse;
options.inverse = fn;
- return Ember.Handlebars.helpers.boundIf.call(options.contexts[0], context, options);
+ return helpers.boundIf.call(options.contexts[0], context, options);
});
/**
@@ -201,7 +204,7 @@ Ember.Handlebars.registerHelper('unless', function(context, options) {
@param {Hash} options
@returns {String} HTML string
*/
-Ember.Handlebars.registerHelper('bindAttr', function(options) {
+EmberHandlebars.registerHelper('bindAttr', function(options) {
var attrs = options.hash;
@@ -219,7 +222,7 @@ Ember.Handlebars.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.Handlebars.bindClasses(this, classBindings, view, dataId);
+ var classResults = EmberHandlebars.bindClasses(this, classBindings, view, dataId);
ret.push('class="' + classResults.join(' ') + '"');
delete attrs['class'];
}
@@ -281,7 +284,7 @@ Ember.Handlebars.registerHelper('bindAttr', function(options) {
// Add the unique identifier
ret.push('data-bindAttr-' + dataId + '="' + dataId + '"');
- return new Ember.Handlebars.SafeString(ret.join(' '));
+ return new EmberHandlebars.SafeString(ret.join(' '));
});
/**
@@ -310,17 +313,18 @@ Ember.Handlebars.registerHelper('bindAttr', function(options) {
@returns {Array} An array of class names to add
*/
-Ember.Handlebars.bindClasses = function(context, classBindings, view, bindAttrId) {
+EmberHandlebars.bindClasses = function(context, classBindings, view, bindAttrId) {
var ret = [], newClass, value, elem;
// Helper method to retrieve the property from the context and
// determine which class string to return, based on whether it is
// a Boolean or not.
var classStringForProperty = function(property) {
var split = property.split(':'),
- property = split[0],
className = split[1];
+ property = split[0];
+
var val = getPath(context, property);
// If value is a Boolean and true, return the dasherized property | false |
Other | emberjs | ember.js | b4d7b38de0f4b05606420aed2449eea410d29f70.json | Add callbacks for isVisible changes to Ember.View
These callbacks, becameVisible and becameHidden,
will work recursively through the child view
hierarchy if you use isVisible as your mechanism
for controlling visibility.
If you (or a library) manually shows or hides a
view, you may not receive callbacks as expected. | packages/ember-views/lib/views/view.js | @@ -152,9 +152,9 @@ Ember.View = Ember.Object.extend(
If false, the view will appear hidden in DOM.
@type Boolean
- @default true
+ @default null
*/
- isVisible: true,
+ isVisible: null,
/**
Array of child views. You should never edit this array directly.
@@ -569,6 +569,9 @@ Ember.View = Ember.Object.extend(
// Schedule the DOM element to be created and appended to the given
// element after bindings have synchronized.
this._insertElementLater(function() {
+ if (get(this, 'isVisible') === null) {
+ set(this, 'isVisible', true);
+ }
this.$().appendTo(target);
});
@@ -927,7 +930,7 @@ Ember.View = Ember.Object.extend(
buffer.attr('role', role);
}
- if (!get(this, 'isVisible')) {
+ if (get(this, 'isVisible') === false) {
buffer.style('display', 'none');
}
},
@@ -1189,16 +1192,64 @@ Ember.View = Ember.Object.extend(
return view;
},
+ becameVisible: Ember.K,
+ becameHidden: Ember.K,
+
/**
@private
When the view's `isVisible` property changes, toggle the visibility
element of the actual DOM element.
*/
_isVisibleDidChange: Ember.observer(function() {
- this.$().toggle(get(this, 'isVisible'));
+ var isVisible = get(this, 'isVisible');
+
+ this.$().toggle(isVisible);
+
+ if (this._isAncestorHidden()) { return; }
+
+ if (isVisible) {
+ this._notifyBecameVisible();
+ } else {
+ this._notifyBecameHidden();
+ }
}, 'isVisible'),
+ _notifyBecameVisible: function() {
+ this.becameVisible();
+
+ this.forEachChildView(function(view) {
+ var isVisible = get(view, 'isVisible');
+
+ if (isVisible || isVisible === null) {
+ view._notifyBecameVisible();
+ }
+ });
+ },
+
+ _notifyBecameHidden: function() {
+ this.becameHidden();
+ this.forEachChildView(function(view) {
+ var isVisible = get(view, 'isVisible');
+
+ if (isVisible || isVisible === null) {
+ view._notifyBecameHidden();
+ }
+ });
+ },
+
+ _isAncestorHidden: function() {
+ var parent = get(this, 'parentView');
+
+ while (parent) {
+ if (get(parent, 'isVisible') === false) { return true; }
+
+ parent = get(parent, 'parentView');
+ }
+
+ return false;
+ },
+
clearBuffer: function() {
this.invokeRecursively(function(view) {
meta(view)['Ember.View'].buffer = null; | true |
Other | emberjs | ember.js | b4d7b38de0f4b05606420aed2449eea410d29f70.json | Add callbacks for isVisible changes to Ember.View
These callbacks, becameVisible and becameHidden,
will work recursively through the child view
hierarchy if you use isVisible as your mechanism
for controlling visibility.
If you (or a library) manually shows or hides a
view, you may not receive callbacks as expected. | packages/ember-views/tests/views/view/is_visible_test.js | @@ -0,0 +1,201 @@
+var get = Ember.get, set = Ember.set;
+
+var View, view, parentBecameVisible, childBecameVisible, grandchildBecameVisible;
+var parentBecameHidden, childBecameHidden, grandchildBecameHidden;
+
+module("Ember.View#isVisible", {
+ setup: function() {
+ parentBecameVisible=0;
+ childBecameVisible=0;
+ grandchildBecameVisible=0;
+ parentBecameHidden=0;
+ childBecameHidden=0;
+ grandchildBecameHidden=0;
+
+ View = Ember.ContainerView.extend({
+ childViews: ['child'],
+ becameVisible: function() { parentBecameVisible++; },
+ becameHidden: function() { parentBecameHidden++; },
+
+ child: Ember.ContainerView.extend({
+ childViews: ['grandchild'],
+ becameVisible: function() { childBecameVisible++; },
+ becameHidden: function() { childBecameHidden++; },
+
+ grandchild: Ember.View.extend({
+ template: function() { return "seems weird bro"; },
+ becameVisible: function() { grandchildBecameVisible++; },
+ becameHidden: function() { grandchildBecameHidden++; }
+ })
+ })
+ });
+ },
+
+ teardown: function() {
+ if (view) { view.destroy(); }
+ }
+});
+
+test("should hide views when isVisible is false", function() {
+ var view = Ember.View.create({
+ isVisible: false
+ });
+
+ Ember.run(function() {
+ view.append();
+ });
+
+ ok(view.$().is(':hidden'), "the view is hidden");
+
+ set(view, 'isVisible', true);
+ ok(view.$().is(':visible'), "the view is visible");
+ view.remove();
+});
+
+test("should hide element if isVisible is false before element is created", function() {
+ var view = Ember.View.create({
+ isVisible: false
+ });
+
+ ok(!get(view, 'isVisible'), "precond - view is not visible");
+
+ set(view, 'template', function() { return "foo"; });
+
+ Ember.run(function() {
+ view.append();
+ });
+
+ ok(view.$().is(':hidden'), "should be hidden");
+
+ view.remove();
+ set(view, 'isVisible', true);
+
+ Ember.run(function() {
+ view.append();
+ });
+
+ ok(view.$().is(':visible'), "view should be visible");
+
+ Ember.run(function() {
+ view.remove();
+ });
+});
+
+test("view should be notified after isVisible is set to false and the element has been hidden", function() {
+ view = View.create({ isVisible: false });
+
+ Ember.run(function() {
+ view.append();
+ });
+
+ ok(view.$().is(':hidden'), "precond - view is hidden when appended");
+
+ Ember.run(function() {
+ view.set('isVisible', true);
+ });
+
+ ok(view.$().is(':visible'), "precond - view is now visible");
+ equal(parentBecameVisible, 1);
+ equal(childBecameVisible, 1);
+ equal(grandchildBecameVisible, 1);
+});
+
+test("view should be notified after isVisible is set to false and the element has been hidden", function() {
+ view = View.create({ isVisible: true });
+ var childView = view.get('childViews').objectAt(0);
+ var grandchildView = childView.get('childViews').objectAt(0);
+
+ Ember.run(function() {
+ view.append();
+ });
+
+ ok(view.$().is(':visible'), "precond - view is visible when appended");
+
+ Ember.run(function() {
+ childView.set('isVisible', false);
+ });
+
+ ok(childView.$().is(':hidden'), "precond - view is now hidden");
+
+ equal(childBecameHidden, 1);
+ equal(grandchildBecameHidden, 1);
+});
+
+test("view should be notified after isVisible is set to true and the element has been shown", function() {
+ view = View.create({ isVisible: false });
+ var childView = view.get('childViews').objectAt(0);
+ var grandchildView = childView.get('childViews').objectAt(0);
+
+ Ember.run(function() {
+ view.append();
+ });
+
+ ok(view.$().is(':hidden'), "precond - view is hidden when appended");
+
+ Ember.run(function() {
+ view.set('isVisible', true);
+ });
+
+ ok(view.$().is(':visible'), "precond - view is now visible");
+
+ equal(parentBecameVisible, 1);
+ equal(childBecameVisible, 1);
+ equal(grandchildBecameVisible, 1);
+});
+
+test("if a view descends from a hidden view, making isVisible true should not trigger becameVisible", function() {
+ view = View.create({ isVisible: true });
+ var childView = view.get('childViews').objectAt(0);
+ var grandchildView = childView.get('childViews').objectAt(0);
+
+ Ember.run(function() {
+ view.append();
+ });
+
+ ok(view.$().is(':visible'), "precond - view is visible when appended");
+
+ Ember.run(function() {
+ childView.set('isVisible', false);
+ });
+
+ Ember.run(function() {
+ view.set('isVisible', false);
+ });
+
+ childBecameVisible = 0;
+ grandchildBecameVisible = 0;
+
+ Ember.run(function() {
+ childView.set('isVisible', true);
+ });
+
+ equal(childBecameVisible, 0, "the child did not become visible");
+ equal(grandchildBecameVisible, 0, "the grandchild did not become visible");
+});
+
+test("if a child view becomes visible while its parent is hidden, if its parent later becomes visible, it receives a becameVisible callback", function() {
+ view = View.create({ isVisible: false });
+ var childView = view.get('childViews').objectAt(0);
+ var grandchildView = childView.get('childViews').objectAt(0);
+
+ Ember.run(function() {
+ view.append();
+ });
+
+ ok(view.$().is(':hidden'), "precond - view is hidden when appended");
+
+ Ember.run(function() {
+ childView.set('isVisible', true);
+ });
+
+ equal(childBecameVisible, 0, "child did not become visible since parent is hidden");
+ equal(grandchildBecameVisible, 0, "grandchild did not become visible since parent is hidden");
+
+ Ember.run(function() {
+ view.set('isVisible', true);
+ });
+
+ equal(parentBecameVisible, 1);
+ equal(childBecameVisible, 1);
+ equal(grandchildBecameVisible, 1);
+}); | true |
Other | emberjs | ember.js | b4d7b38de0f4b05606420aed2449eea410d29f70.json | Add callbacks for isVisible changes to Ember.View
These callbacks, becameVisible and becameHidden,
will work recursively through the child view
hierarchy if you use isVisible as your mechanism
for controlling visibility.
If you (or a library) manually shows or hides a
view, you may not receive callbacks as expected. | packages/ember-views/tests/views/view/render_test.js | @@ -91,51 +91,6 @@ test("should render child views with a different tagName", function() {
equals(view.$('aside').length, 1);
});
-test("should hide views when isVisible is false", function() {
- var view = Ember.View.create({
- isVisible: false
- });
-
- Ember.run(function() {
- view.append();
- });
-
- ok(view.$().is(':hidden'), "the view is hidden");
-
- set(view, 'isVisible', true);
- ok(view.$().is(':visible'), "the view is visible");
- view.remove();
-});
-
-test("should hide element if isVisible is false before element is created", function() {
- var view = Ember.View.create({
- isVisible: false
- });
-
- ok(!get(view, 'isVisible'), "precond - view is not visible");
-
- set(view, 'template', function() { return "foo"; });
-
- Ember.run(function() {
- view.append();
- });
-
- ok(view.$().is(':hidden'), "should be hidden");
-
- view.remove();
- set(view, 'isVisible', true);
-
- Ember.run(function() {
- view.append();
- });
-
- ok(view.$().is(':visible'), "view should be visible");
-
- Ember.run(function() {
- view.remove();
- });
-});
-
test("should add ember-view to views", function() {
var view = Ember.View.create();
| true |
Other | emberjs | ember.js | f41e667d5cf13b7284cb1cad6f44d568f35ef279.json | add tests for Ember.isGlobalPath | packages/ember-metal/tests/accessors/isGlobalPath_test.js | @@ -0,0 +1,22 @@
+// ==========================================================================
+// Project: Ember Runtime
+// Copyright: ©2011 Strobe Inc. and contributors.
+// License: Licensed under MIT license (see license.js)
+// ==========================================================================
+
+module('Ember.isGlobalPath');
+
+test("global path's are recognized", function(){
+ ok( Ember.isGlobalPath('App.myProperty') );
+ ok( Ember.isGlobalPath('App.myProperty.subProperty') );
+});
+
+test("if there is a 'this' in the path, it's not a global path", function(){
+ ok( !Ember.isGlobalPath('this.myProperty') );
+ ok( !Ember.isGlobalPath('this') );
+});
+
+test("if the path starts with a lowercase character, it is not a global path", function(){
+ ok( !Ember.isGlobalPath('myObj') );
+ ok( !Ember.isGlobalPath('myObj.SecondProperty') );
+});
\ No newline at end of file | false |
Other | emberjs | ember.js | a0fadf121fe08bec3cca433057374dbd466d2308.json | Fix unbound helper when used with {{this}}
When the #each helper is used, the unbound helper didn't
work with {{this}}. | packages/ember-handlebars/tests/handlebars_test.js | @@ -1289,6 +1289,17 @@ test("should be able to use standard Handlebars #each helper", function() {
equals(view.$().html(), "abc");
});
+test("should be able to use unbound helper in #each helper", function() {
+ view = Ember.View.create({
+ items: Ember.A(['a', 'b', 'c']),
+ template: Ember.Handlebars.compile("{{#each items}}{{unbound this}}{{/each}}")
+ });
+
+ appendView();
+
+ equals(view.$().text(), "abc");
+});
+
module("Templates redrawing and bindings", {
setup: function(){
MyApp = Ember.Object.create({}); | true |
Other | emberjs | ember.js | a0fadf121fe08bec3cca433057374dbd466d2308.json | Fix unbound helper when used with {{this}}
When the #each helper is used, the unbound helper didn't
work with {{this}}. | packages/ember-metal/lib/accessors.js | @@ -260,6 +260,11 @@ Ember.getPath = function(root, path) {
var hasThis, hasStar, isGlobal;
if (!path && 'string'===typeof root) {
+ // Helpers that operate with 'this' within an #each
+ if (path === '') {
+ return root;
+ }
+
path = root;
root = null;
} | true |
Other | emberjs | ember.js | 3edefeae22cf7c84fafc026230c26fc4af75d608.json | Remove unnecessary set watching to zero.
Once all the refs are gone, watching is no longer used, so there is no reason to set its count back to 0. | packages/ember-metal/lib/watching.js | @@ -549,18 +549,16 @@ var propertyDidChange = Ember.propertyDidChange = function(obj, keyName) {
@returns {void}
*/
Ember.destroy = function (obj) {
- var meta = obj[META_KEY], chains, watching, paths, path;
+ var meta = obj[META_KEY], chains, paths, path;
if (meta) {
obj[META_KEY] = null;
// remove chains to remove circular references that would prevent GC
chains = meta.chains;
if (chains) {
- watching = meta.watching;
paths = chains._paths;
for(path in paths) {
if (!(paths[path] > 0)) continue; // this check will also catch non-number vals.
chains.remove(path);
- watching[path] = 0;
}
}
} | false |
Other | emberjs | ember.js | 901b0f64cbd03d4dcf75bb616ef2b500b2dab449.json | Add chain removal to Ember.destroy
This breaks circular references so Objects can be garbage collected after being destroyed. | packages/ember-metal/lib/properties.js | @@ -401,16 +401,3 @@ Ember.createPrototype = function(obj, props) {
if (META_KEY in ret) Ember.rewatch(ret); // setup watch chains if needed.
return ret;
};
-
-
-/**
- Tears down the meta on an object so that it can be garbage collected.
- Multiple calls will have no effect.
-
- @param {Object} obj the object to destroy
- @returns {void}
-*/
-Ember.destroy = function(obj) {
- if (obj[META_KEY]) obj[META_KEY] = null;
-};
- | true |
Other | emberjs | ember.js | 901b0f64cbd03d4dcf75bb616ef2b500b2dab449.json | Add chain removal to Ember.destroy
This breaks circular references so Objects can be garbage collected after being destroyed. | packages/ember-metal/lib/watching.js | @@ -19,6 +19,7 @@ var normalizeTuple = Ember.normalizeTuple.primitive;
var normalizePath = Ember.normalizePath;
var SIMPLE_PROPERTY = Ember.SIMPLE_PROPERTY;
var GUID_KEY = Ember.GUID_KEY;
+var META_KEY = Ember.META_KEY;
var notifyObservers = Ember.notifyObservers;
var FIRST_KEY = /^([^\.\*]+)/;
@@ -539,3 +540,28 @@ var propertyDidChange = Ember.propertyDidChange = function(obj, keyName) {
chainsDidChange(obj, keyName);
Ember.notifyObservers(obj, keyName);
};
+
+/**
+ Tears down the meta on an object so that it can be garbage collected.
+ Multiple calls will have no effect.
+
+ @param {Object} obj the object to destroy
+ @returns {void}
+*/
+Ember.destroy = function (obj) {
+ var meta = obj[META_KEY], chains, watching, paths, path;
+ if (meta) {
+ obj[META_KEY] = null;
+ // remove chains to remove circular references that would prevent GC
+ chains = meta.chains;
+ if (chains) {
+ watching = meta.watching;
+ paths = chains._paths;
+ for(path in paths) {
+ if (!(paths[path] > 0)) continue; // this check will also catch non-number vals.
+ chains.remove(path);
+ watching[path] = 0;
+ }
+ }
+ }
+}; | true |
Other | emberjs | ember.js | 901b0f64cbd03d4dcf75bb616ef2b500b2dab449.json | Add chain removal to Ember.destroy
This breaks circular references so Objects can be garbage collected after being destroyed. | packages/ember-metal/tests/watching/watch_test.js | @@ -123,3 +123,19 @@ testBoth('watching a global object that does not yet exist should queue', functi
Global = null; // reset
});
+testBoth('destroy should tear down chainWatchers', function(get, set) {
+
+ Global = { foo: 'bar' };
+ var obj = {};
+
+ Ember.watch(obj, 'Global.foo');
+
+ var metaGlobal = Ember.meta(Global);
+ equals(metaGlobal.watching.foo, 1, 'should be watching Global.foo');
+
+ Ember.destroy(obj);
+
+ equals(metaGlobal.watching.foo, 0, 'should not be watching Global.foo');
+
+ Global = null; // reset
+}); | true |
Other | emberjs | ember.js | 901b0f64cbd03d4dcf75bb616ef2b500b2dab449.json | Add chain removal to Ember.destroy
This breaks circular references so Objects can be garbage collected after being destroyed. | packages/ember-runtime/lib/system/core_object.js | @@ -101,7 +101,7 @@ CoreObject.PrototypeMixin = Ember.Mixin.create(
@private
*/
_scheduledDestroy: function() {
- this[Ember.META_KEY] = null;
+ Ember.destroy(this);
},
bind: function(to, from) { | true |
Other | emberjs | ember.js | 3a07b4df1ee579b9fb92eb26db495120c37a870f.json | Unify attribute bindings logic and fix some bugs
when bound value is null or undefined. | packages/ember-handlebars/lib/helpers/binding.js | @@ -232,20 +232,7 @@ Ember.Handlebars.registerHelper('bindAttr', function(options) {
return;
}
- var currentValue = elem.attr(attr);
-
- // A false result will remove the attribute from the element. This is
- // to support attributes such as disabled, whose presence is meaningful.
- if (result === false && currentValue) {
- elem.removeAttr(attr);
-
- // Likewise, a true result will set the attribute's name as the value.
- } else if (result === true && currentValue !== attr) {
- elem.attr(attr, attr);
-
- } else if (currentValue !== result) {
- elem.attr(attr, result);
- }
+ Ember.View.applyAttributeBindings(elem, attr, result);
};
/** @private */
@@ -258,15 +245,12 @@ Ember.Handlebars.registerHelper('bindAttr', function(options) {
// unique data id and update the attribute to the new value.
Ember.addObserver(ctx, property, invoker);
- // Use the attribute's name as the value when it is YES
- if (value === true) {
- value = attr;
- }
+ var type = typeof value;
- // Do not add the attribute when the value is false
- if (value !== false) {
- // Return the current value, in the form src="foo.jpg"
+ if ((type === 'string' || (type === 'number' && !isNaN(value)))) {
ret.push(attr + '="' + value + '"');
+ } else if (value && type === 'boolean') {
+ ret.push(attr + '="' + attr + '"');
}
}, this);
| true |
Other | emberjs | ember.js | 3a07b4df1ee579b9fb92eb26db495120c37a870f.json | Unify attribute bindings logic and fix some bugs
when bound value is null or undefined. | packages/ember-views/lib/system/render_buffer.js | @@ -138,15 +138,38 @@ Ember._RenderBuffer = Ember.Object.extend(
return this;
},
+ // duck type attribute functionality like jQuery so a render buffer
+ // can be used like a jQuery object in attribute binding scenarios.
+
/**
Adds an attribute which will be rendered to the element.
@param {String} name The name of the attribute
@param {String} value The value to add to the attribute
- @returns {Ember.RenderBuffer} this
+ @returns {Ember.RenderBuffer|String} this or the current attribute value
*/
attr: function(name, value) {
- get(this, 'elementAttributes')[name] = value;
+ var attributes = get(this, 'elementAttributes');
+
+ if (arguments.length === 1) {
+ return attributes[name]
+ } else {
+ attributes[name] = value;
+ }
+
+ return this;
+ },
+
+ /**
+ Remove an attribute from the list of attributes to render.
+
+ @param {String} name The name of the attribute
+ @returns {Ember.RenderBuffer} this
+ */
+ removeAttr: function(name) {
+ var attributes = get(this, 'elementAttributes');
+ delete attributes[name];
+
return this;
},
| true |
Other | emberjs | ember.js | 3a07b4df1ee579b9fb92eb26db495120c37a870f.json | Unify attribute bindings logic and fix some bugs
when bound value is null or undefined. | packages/ember-views/lib/views/view.js | @@ -430,38 +430,22 @@ Ember.View = Ember.Object.extend(
if (!attributeBindings) { return; }
- attributeBindings.forEach(function(attribute) {
+ attributeBindings.forEach(function(attributeName) {
// Create an observer to add/remove/change the attribute if the
// JavaScript property changes.
var observer = function() {
elem = this.$();
- var currentValue = elem.attr(attribute);
- attributeValue = get(this, attribute);
+ attributeValue = get(this, attributeName);
- type = typeof attributeValue;
-
- if ((type === 'string' || (type === 'number' && !isNaN(attributeValue))) && attributeValue !== currentValue) {
- elem.attr(attribute, attributeValue);
- } else if (attributeValue && type === 'boolean') {
- elem.attr(attribute, attribute);
- } else if (!attributeValue) {
- elem.removeAttr(attribute);
- }
+ Ember.View.applyAttributeBindings(elem, attributeName, attributeValue)
};
- addObserver(this, attribute, observer);
+ addObserver(this, attributeName, observer);
// Determine the current value and add it to the render buffer
// if necessary.
- attributeValue = get(this, attribute);
- type = typeof attributeValue;
-
- if (type === 'string' || type === 'number') {
- buffer.attr(attribute, attributeValue);
- } else if (attributeValue && type === 'boolean') {
- // Apply boolean attributes in the form attribute="attribute"
- buffer.attr(attribute, attribute);
- }
+ attributeValue = get(this, attributeName);
+ Ember.View.applyAttributeBindings(buffer, attributeName, attributeValue);
}, this);
},
@@ -1312,3 +1296,17 @@ Ember.View.views = {};
// at view initialization time. This happens in Ember.ContainerView's init
// method.
Ember.View.childViewsProperty = childViewsProperty;
+
+Ember.View.applyAttributeBindings = function(elem, name, value) {
+ var type = typeof value;
+ var currentValue = elem.attr(name);
+
+ // if this changes, also change the logic in ember-handlebars/lib/helpers/binding.js
+ if ((type === 'string' || (type === 'number' && !isNaN(value))) && value !== currentValue) {
+ elem.attr(name, value);
+ } else if (value && type === 'boolean') {
+ elem.attr(name, name);
+ } else if (!value) {
+ elem.removeAttr(name);
+ }
+}; | true |
Other | emberjs | ember.js | 3a07b4df1ee579b9fb92eb26db495120c37a870f.json | Unify attribute bindings logic and fix some bugs
when bound value is null or undefined. | packages/ember-views/tests/views/view/attribute_bindings_test.js | @@ -10,7 +10,32 @@ require('ember-views/views/view');
module("Ember.View - Attribute Bindings");
-test("should render and update attribute bindings", function() {
+test("should render attribute bindings", function() {
+ var view = Ember.View.create({
+ classNameBindings: ['priority', 'isUrgent', 'isClassified:classified', 'canIgnore'],
+ attributeBindings: ['type', 'exploded', 'destroyed', 'exists', 'nothing', 'notDefined', 'notNumber', 'explosions'],
+
+ type: 'submit',
+ exploded: false,
+ destroyed: false,
+ exists: true,
+ nothing: null,
+ notDefined: undefined,
+ notNumber: NaN,
+ });
+
+ view.createElement();
+
+ equals(view.$().attr('type'), 'submit', "updates type attribute");
+ ok(!view.$().attr('exploded'), "removes exploded attribute when false");
+ ok(!view.$().attr('destroyed'), "removes destroyed attribute when false");
+ ok(view.$().attr('exists'), "adds exists attribute when true");
+ ok(!view.$().attr('nothing'), "removes nothing attribute when null");
+ ok(!view.$().attr('notDefined'), "removes notDefined attribute when undefined");
+ ok(!view.$().attr('notNumber'), "removes notNumber attribute when NaN");
+});
+
+test("should update attribute bindings", function() {
var view = Ember.View.create({
classNameBindings: ['priority', 'isUrgent', 'isClassified:classified', 'canIgnore'],
attributeBindings: ['type', 'exploded', 'destroyed', 'exists', 'nothing', 'notDefined', 'notNumber', 'explosions'], | true |
Other | emberjs | ember.js | 56acdc1fdcdcada0d850c64eb77f76c920f93f28.json | Reduce dereferencing of Array.prototype.slice | packages/ember-metal/lib/mixin.js | @@ -16,6 +16,7 @@ var Mixin, MixinDelegate, REQUIRED, Alias;
var classToString, superClassString;
var a_map = Array.prototype.map;
+var a_slice = Array.prototype.slice;
var EMPTY_META = {}; // dummy for non-writable meta
var META_SKIP = { __emberproto__: true, __ember_count__: true };
@@ -263,7 +264,7 @@ function applyMixin(obj, mixins, partial) {
}
Ember.mixin = function(obj) {
- var args = Array.prototype.slice.call(arguments, 1);
+ var args = a_slice.call(arguments, 1);
return applyMixin(obj, args, false);
};
@@ -277,7 +278,7 @@ Mixin = function() { return initMixin(this, arguments); };
Mixin._apply = applyMixin;
Mixin.applyPartial = function(obj) {
- var args = Array.prototype.slice.call(arguments, 1);
+ var args = a_slice.call(arguments, 1);
return applyMixin(obj, args, true);
};
@@ -349,7 +350,7 @@ Mixin.prototype.detect = function(obj) {
Mixin.prototype.without = function() {
var ret = new Mixin(this);
- ret._without = Array.prototype.slice.call(arguments);
+ ret._without = a_slice.call(arguments);
return ret;
};
@@ -511,13 +512,13 @@ Ember.MixinDelegate = MixinDelegate;
//
Ember.observer = function(func) {
- var paths = Array.prototype.slice.call(arguments, 1);
+ var paths = a_slice.call(arguments, 1);
func.__ember_observes__ = paths;
return func;
};
Ember.beforeObserver = function(func) {
- var paths = Array.prototype.slice.call(arguments, 1);
+ var paths = a_slice.call(arguments, 1);
func.__ember_observesBefore__ = paths;
return func;
}; | true |
Other | emberjs | ember.js | 56acdc1fdcdcada0d850c64eb77f76c920f93f28.json | Reduce dereferencing of Array.prototype.slice | packages/ember-runtime/lib/ext/function.js | @@ -7,6 +7,8 @@
require('ember-runtime/core');
+var a_slice = Array.prototype.slice;
+
if (Ember.EXTEND_PROTOTYPES) {
Function.prototype.property = function() {
@@ -15,12 +17,12 @@ if (Ember.EXTEND_PROTOTYPES) {
};
Function.prototype.observes = function() {
- this.__ember_observes__ = Array.prototype.slice.call(arguments);
+ this.__ember_observes__ = a_slice.call(arguments);
return this;
};
Function.prototype.observesBefore = function() {
- this.__ember_observesBefore__ = Array.prototype.slice.call(arguments);
+ this.__ember_observesBefore__ = a_slice.call(arguments);
return this;
};
| true |
Other | emberjs | ember.js | 56acdc1fdcdcada0d850c64eb77f76c920f93f28.json | Reduce dereferencing of Array.prototype.slice | packages/ember-runtime/lib/mixins/enumerable.js | @@ -13,6 +13,7 @@
//
var get = Ember.get, set = Ember.set;
+var a_slice = Array.prototype.slice;
var contexts = [];
function popCtx() {
@@ -522,7 +523,7 @@ Ember.Enumerable = Ember.Mixin.create( /** @lends Ember.Enumerable */ {
*/
invoke: function(methodName) {
var args, ret = [];
- if (arguments.length>1) args = Array.prototype.slice.call(arguments, 1);
+ if (arguments.length>1) args = a_slice.call(arguments, 1);
this.forEach(function(x, idx) {
var method = x && x[methodName]; | true |
Other | emberjs | ember.js | 56acdc1fdcdcada0d850c64eb77f76c920f93f28.json | Reduce dereferencing of Array.prototype.slice | packages/ember-views/lib/views/view.js | @@ -9,6 +9,7 @@
require("ember-views/system/render_buffer");
var get = Ember.get, set = Ember.set, addObserver = Ember.addObserver;
var getPath = Ember.getPath, meta = Ember.meta, fmt = Ember.String.fmt;
+var a_slice = Array.prototype.slice;
var childViewsProperty = Ember.computed(function() {
var childViews = get(this, '_childViews');
@@ -300,7 +301,7 @@ Ember.View = Ember.Object.extend(
var fn = state[name];
if (fn) {
- var args = Array.prototype.slice.call(arguments, 1);
+ var args = a_slice.call(arguments, 1);
args.unshift(this);
return fn.apply(this, args); | true |
Other | emberjs | ember.js | bd87a07f16489d4596404cc5523977b7b2a0a7d1.json | Change behavior of Ember.empty for functions | packages/ember-runtime/lib/core.js | @@ -126,7 +126,7 @@ Ember.none = function(obj) {
@returns {Boolean}
*/
Ember.empty = function(obj) {
- return obj === null || obj === undefined || obj.length === 0;
+ return obj === null || obj === undefined || (obj.length === 0 && typeof obj !== 'function');
};
/** | true |
Other | emberjs | ember.js | bd87a07f16489d4596404cc5523977b7b2a0a7d1.json | Change behavior of Ember.empty for functions | packages/ember-runtime/tests/core/type_test.js | @@ -39,18 +39,20 @@ test("Ember.none", function() {
});
test("Ember.empty", function() {
- var string = "string", fn = function() {};
+ var string = "string", fn = function() {},
+ object = {length: 0};
equals(true, Ember.empty(null), "for null");
equals(true, Ember.empty(undefined), "for undefined");
equals(true, Ember.empty(""), "for an empty String");
equals(false, Ember.empty(true), "for true");
equals(false, Ember.empty(false), "for false");
equals(false, Ember.empty(string), "for a String");
- equals(true, Ember.empty(fn), "for a Function");
+ equals(false, Ember.empty(fn), "for a Function");
equals(false, Ember.empty(0), "for 0");
equals(true, Ember.empty([]), "for an empty Array");
equals(false, Ember.empty({}), "for an empty Object");
+ equals(true, Ember.empty(object), "for an Object that has zero 'length'");
});
test("Ember.isArray" ,function(){ | true |
Other | emberjs | ember.js | 85ef51674431f3a04dfe806522a9c711276cf645.json | Pass meta instead of looking up twice. | packages/ember-metal/lib/watching.js | @@ -38,14 +38,14 @@ function isKeyName(path) {
//
var DEP_SKIP = { __emberproto__: true }; // skip some keys and toString
-function iterDeps(method, obj, depKey, seen) {
+function iterDeps(method, obj, depKey, seen, meta) {
var guid = guidFor(obj);
if (!seen[guid]) seen[guid] = {};
if (seen[guid][depKey]) return ;
seen[guid][depKey] = true;
- var deps = meta(obj, false).deps;
+ var deps = meta.deps;
deps = deps && deps[depKey];
if (deps) {
for(var key in deps) {
@@ -59,18 +59,18 @@ function iterDeps(method, obj, depKey, seen) {
var WILL_SEEN, DID_SEEN;
// called whenever a property is about to change to clear the cache of any dependent keys (and notify those properties of changes, etc...)
-function dependentKeysWillChange(obj, depKey) {
+function dependentKeysWillChange(obj, depKey, meta) {
var seen = WILL_SEEN, top = !seen;
if (top) seen = WILL_SEEN = {};
- iterDeps(propertyWillChange, obj, depKey, seen);
+ iterDeps(propertyWillChange, obj, depKey, seen, meta);
if (top) WILL_SEEN = null;
}
// called whenever a property has just changed to update dependent keys
-function dependentKeysDidChange(obj, depKey) {
+function dependentKeysDidChange(obj, depKey, meta) {
var seen = DID_SEEN, top = !seen;
if (top) seen = DID_SEEN = {};
- iterDeps(propertyDidChange, obj, depKey, seen);
+ iterDeps(propertyDidChange, obj, depKey, seen, meta);
if (top) DID_SEEN = null;
}
@@ -506,7 +506,7 @@ var propertyWillChange = Ember.propertyWillChange = function(obj, keyName) {
var m = meta(obj, false), proto = m.proto, desc = m.descs[keyName];
if (proto === obj) return ;
if (desc && desc.willChange) desc.willChange(obj, keyName);
- dependentKeysWillChange(obj, keyName);
+ dependentKeysWillChange(obj, keyName, m);
chainsWillChange(obj, keyName);
Ember.notifyBeforeObservers(obj, keyName);
};
@@ -532,7 +532,7 @@ var propertyDidChange = Ember.propertyDidChange = function(obj, keyName) {
var m = meta(obj, false), proto = m.proto, desc = m.descs[keyName];
if (proto === obj) return ;
if (desc && desc.didChange) desc.didChange(obj, keyName);
- dependentKeysDidChange(obj, keyName);
+ dependentKeysDidChange(obj, keyName, m);
chainsDidChange(obj, keyName);
Ember.notifyObservers(obj, keyName);
}; | false |
Other | emberjs | ember.js | 9e099c1ffd0c49f9ffdb08c9c8adc9a5c2ecf0cb.json | Improve performance of Ember.A(), especially when
native array enhancements have already been applied. | packages/ember-runtime/lib/system/native_array.js | @@ -130,7 +130,7 @@ Ember.NativeArray = NativeArray;
*/
Ember.A = function(arr){
if (arr === undefined) { arr = []; }
- return Ember.NativeArray.apply(Array.prototype.slice.apply(arr));
+ return Ember.NativeArray.apply(arr);
};
/**
@@ -141,6 +141,8 @@ Ember.A = function(arr){
*/
Ember.NativeArray.activate = function() {
NativeArray.apply(Array.prototype);
+
+ Ember.A = function(arr) { return arr || []; }
};
if (Ember.EXTEND_PROTOTYPES) Ember.NativeArray.activate(); | false |
Other | emberjs | ember.js | 13052de12a3f380193a80fb7e47751e26ada7122.json | Remove ember_asserts from hot code paths | packages/ember-metal/lib/events.js | @@ -167,7 +167,6 @@ function watchedEvents(obj) {
}
function sendEvent(obj, eventName) {
- ember_assert("You must pass an object and event name to Ember.sendEvent", !!obj && !!eventName);
// first give object a chance to handle it
if (obj !== Ember && 'function' === typeof obj.sendEvent) { | true |
Other | emberjs | ember.js | 13052de12a3f380193a80fb7e47751e26ada7122.json | Remove ember_asserts from hot code paths | packages/ember-metal/lib/utils.js | @@ -172,8 +172,6 @@ if (Object.freeze) Object.freeze(EMPTY_META);
@returns {Hash}
*/
Ember.meta = function meta(obj, writable) {
-
- ember_assert("You must pass an object to Ember.meta. This was probably called from Ember internals, so you probably called a Ember method with undefined that was expecting an object", obj != undefined);
var ret = obj[META_KEY];
if (writable===false) return ret || EMPTY_META; | true |
Other | emberjs | ember.js | 13052de12a3f380193a80fb7e47751e26ada7122.json | Remove ember_asserts from hot code paths | packages/ember-metal/lib/watching.js | @@ -35,16 +35,16 @@ function isKeyName(path) {
// ..........................................................
// DEPENDENT KEYS
-//
+//
var DEP_SKIP = { __emberproto__: true }; // skip some keys and toString
function iterDeps(method, obj, depKey, seen) {
-
+
var guid = guidFor(obj);
if (!seen[guid]) seen[guid] = {};
if (seen[guid][depKey]) return ;
seen[guid][depKey] = true;
-
+
var deps = meta(obj, false).deps;
deps = deps && deps[depKey];
if (deps) { | true |
Other | emberjs | ember.js | f77832499898d970ea665a92333a3ed2ec0d663c.json | Add missing semicolon | packages/ember-metal/tests/run_loop/unwind_test.js | @@ -11,7 +11,7 @@ test('RunLoop unwinds despite unhandled exception', function() {
raises(function(){
Ember.run(function() {
- Ember.run.schedule('actions', function() { throw new Error("boom!") });
+ Ember.run.schedule('actions', function() { throw new Error("boom!"); });
});
}, Error, "boom!");
| false |
Other | emberjs | ember.js | b15342c06210f1eb60392f6eebc86ea6b6dd4d0e.json | allow use of multiple {{bindAttr}}s per element | packages/ember-handlebars/lib/helpers/binding.js | @@ -218,7 +218,7 @@ Ember.Handlebars.registerHelper('bindAttr', function(options) {
ember_assert(fmt("Attributes must be numbers, strings or booleans, not %@", [result]), result == null || typeof result === 'number' || typeof result === 'string' || typeof result === 'boolean');
- var elem = view.$("[data-handlebars-id='" + dataId + "']");
+ var elem = view.$("[data-bindAttr-" + dataId + "='" + dataId + "']");
// If we aren't able to find the element, it means the element
// to which we were bound has been removed from the view.
@@ -267,7 +267,7 @@ Ember.Handlebars.registerHelper('bindAttr', function(options) {
}, this);
// Add the unique identifier
- ret.push('data-handlebars-id="' + dataId + '"');
+ ret.push('data-bindAttr-' + dataId + '="' + dataId + '"');
return new Ember.Handlebars.SafeString(ret.join(' '));
});
@@ -292,12 +292,12 @@ Ember.Handlebars.registerHelper('bindAttr', function(options) {
@param {Ember.View} view
The view in which observers should look for the element to update
- @param {String} id
- Optional id use to lookup elements
+ @param {Srting} bindAttrId
+ Optional bindAttr id used to lookup elements
@returns {Array} An array of class names to add
*/
-Ember.Handlebars.bindClasses = function(context, classBindings, view, id) {
+Ember.Handlebars.bindClasses = function(context, classBindings, view, bindAttrId) {
var ret = [], newClass, value, elem;
// Helper method to retrieve the property from the context and
@@ -349,7 +349,7 @@ Ember.Handlebars.bindClasses = function(context, classBindings, view, id) {
observer = function() {
// Get the current value of the property
newClass = classStringForProperty(binding);
- elem = id ? view.$("[data-handlebars-id='" + id + "']") : view.$();
+ elem = bindAttrId ? view.$("[data-bindAttr-" + bindAttrId + "='" + bindAttrId + "']") : view.$();
// If we can't find the element anymore, a parent template has been
// re-rendered and we've been nuked. Remove the observer. | true |
Other | emberjs | ember.js | b15342c06210f1eb60392f6eebc86ea6b6dd4d0e.json | allow use of multiple {{bindAttr}}s per element | packages/ember-handlebars/tests/handlebars_test.js | @@ -1046,6 +1046,59 @@ test("should be able to bind element attributes using {{bindAttr}}", function()
equals(view.$('img').attr('alt'), "Nanananana Ember!", "updates alt attribute when title property is computed");
});
+test("should be able to bind use {{bindAttr}} more than once on an element", function() {
+ var template = Ember.Handlebars.compile('<img {{bindAttr src="content.url"}} {{bindAttr alt="content.title"}}>');
+
+ view = Ember.View.create({
+ template: template,
+ content: Ember.Object.create({
+ url: "http://www.emberjs.com/assets/images/logo.png",
+ title: "The SproutCore Logo"
+ })
+ });
+
+ appendView();
+
+ equals(view.$('img').attr('src'), "http://www.emberjs.com/assets/images/logo.png", "sets src attribute");
+ equals(view.$('img').attr('alt'), "The SproutCore Logo", "sets alt attribute");
+
+ Ember.run(function() {
+ setPath(view, 'content.title', "El logo de Eember");
+ });
+
+ equals(view.$('img').attr('alt'), "El logo de Eember", "updates alt attribute when content's title attribute changes");
+
+ Ember.run(function() {
+ set(view, 'content', Ember.Object.create({
+ url: "http://www.thegooglez.com/theydonnothing",
+ title: "I CAN HAZ SEARCH"
+ }));
+ });
+
+ equals(view.$('img').attr('alt'), "I CAN HAZ SEARCH", "updates alt attribute when content object changes");
+
+ Ember.run(function() {
+ set(view, 'content', {
+ url: "http://www.emberjs.com/assets/images/logo.png",
+ title: "The SproutCore Logo"
+ });
+ });
+
+ equals(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({
+ url: "http://www.emberjs.com/assets/images/logo.png",
+ title: Ember.computed(function() {
+ return "Nanananana Ember!";
+ })
+ }));
+ });
+
+ equals(view.$('img').attr('alt'), "Nanananana Ember!", "updates alt attribute when title property is computed");
+
+});
+
test("should not reset cursor position when text field receives keyUp event", function() {
view = Ember.TextField.create({
value: "Broseidon, King of the Brocean" | true |
Other | emberjs | ember.js | 86edd79b43134c8d20490b6979f6a21f8b77b39c.json | Update SC reference to Ember | packages/ember-states/tests/state_manager_test.js | @@ -178,12 +178,12 @@ test("it automatically transitions to a default state specified using the initia
});
test("it reports the view associated with the current view state, if any", function() {
- var view = SC.View.create();
+ var view = Ember.View.create();
- stateManager = SC.StateManager.create({
- foo: SC.ViewState.create({
+ stateManager = Ember.StateManager.create({
+ foo: Ember.ViewState.create({
view: view,
- bar: SC.State.create()
+ bar: Ember.State.create()
})
});
| false |
Other | emberjs | ember.js | 16522c45f2a0e801a542f7ad18777924e728701c.json | Show gzipped size for `rake dist` | Rakefile | @@ -92,16 +92,24 @@ distributions.each do |name, libraries|
# Minified distribution
file "dist/#{name}.min.js" => "dist/#{name}.js" do
- puts "Generating #{name}.min.js"
+ require 'zlib'
+
+ print "Generating #{name}.min.js... "
+ STDOUT.flush
File.open("dist/#{name}.prod.js", "w") do |file|
file.puts strip_ember_assert("dist/#{name}.js")
end
+ minified_code = uglify("dist/#{name}.prod.js")
File.open("dist/#{name}.min.js", "w") do |file|
- file.puts uglify("dist/#{name}.prod.js")
+ file.puts minified_code
end
+ gzipped_kb = Zlib::Deflate.deflate(minified_code).bytes.count / 1024
+
+ puts "#{gzipped_kb} KB gzipped"
+
rm "dist/#{name}.prod.js"
end
end | false |
Other | emberjs | ember.js | df461ea70b3fd71747d96e333d6391ee65671d2f.json | Fix toString() for objects in the Ember namespace | packages/ember-metal/lib/core.js | @@ -26,7 +26,10 @@ if ('undefined' === typeof Ember) {
The core Runtime framework is based on the jQuery API with a number of
performance optimizations.
*/
-Ember = {};
+
+// Create core object. Make it act like an instance of Ember.Namespace so that
+// objects assigned to it are given a sane string representation.
+Ember = { isNamespace: true, toString: function() { return "Ember"; } };
// aliases needed to keep minifiers from removing the global context
if ('undefined' !== typeof window) { | true |
Other | emberjs | ember.js | df461ea70b3fd71747d96e333d6391ee65671d2f.json | Fix toString() for objects in the Ember namespace | packages/ember-metal/lib/mixin.js | @@ -375,6 +375,7 @@ Mixin.prototype.keys = function() {
/** @private - make Mixin's have nice displayNames */
var NAME_KEY = Ember.GUID_KEY+'_name';
+var get = Ember.get;
function processNames(paths, root, seen) {
var idx = paths.length;
@@ -385,7 +386,7 @@ function processNames(paths, root, seen) {
if (obj && obj.toString === classToString) {
obj[NAME_KEY] = paths.join('.');
- } else if (key==='Ember' || (Ember.Namespace && obj instanceof Ember.Namespace)) {
+ } else if (obj && get(obj, 'isNamespace')) {
if (seen[Ember.guidFor(obj)]) continue;
seen[Ember.guidFor(obj)] = true;
processNames(paths, obj, seen);
@@ -406,7 +407,7 @@ function findNamespaces() {
obj = window[prop];
- if (obj && obj instanceof Namespace) {
+ if (obj && get(obj, 'isNamespace')) {
obj[NAME_KEY] = prop;
}
} | true |
Other | emberjs | ember.js | df461ea70b3fd71747d96e333d6391ee65671d2f.json | Fix toString() for objects in the Ember namespace | packages/ember-runtime/lib/system/namespace.js | @@ -20,6 +20,8 @@ require('ember-runtime/system/object');
*/
Ember.Namespace = Ember.Object.extend({
+ isNamespace: true,
+
init: function() {
Ember.Namespace.NAMESPACES.push(this);
Ember.Namespace.PROCESSED = false;
@@ -38,5 +40,5 @@ Ember.Namespace = Ember.Object.extend({
}
});
-Ember.Namespace.NAMESPACES = [];
-Ember.Namespace.PROCESSED = true;
+Ember.Namespace.NAMESPACES = [Ember];
+Ember.Namespace.PROCESSED = false; | true |
Other | emberjs | ember.js | df461ea70b3fd71747d96e333d6391ee65671d2f.json | Fix toString() for objects in the Ember namespace | packages/ember-runtime/tests/system/namespace/base_test.js | @@ -4,6 +4,8 @@
// License: Licensed under MIT license (see license.js)
// ==========================================================================
+var get = Ember.get;
+
module('Ember.Namespace', {
teardown: function() {
if (window.NamespaceA) { window.NamespaceA.destroy(); }
@@ -15,6 +17,10 @@ test('Ember.Namespace should be a subclass of Ember.Object', function() {
ok(Ember.Object.detect(Ember.Namespace));
});
+test("Ember.Namespace should be duck typed", function() {
+ ok(get(Ember.Namespace.create(), 'isNamespace'), "isNamespace property is true");
+});
+
test('Ember.Namespace is found and named', function() {
var nsA = window.NamespaceA = Ember.Namespace.create();
equal(nsA.toString(), "NamespaceA", "namespaces should have a name if they are on window");
@@ -23,7 +29,7 @@ test('Ember.Namespace is found and named', function() {
equal(nsB.toString(), "NamespaceB", "namespaces work if created after the first namespace processing pass");
});
-test("Classes under Ember.Namespace are properly named", function() {
+test("Classes under an Ember.Namespace are properly named", function() {
var nsA = window.NamespaceA = Ember.Namespace.create();
nsA.Foo = Ember.Object.extend();
equal(nsA.Foo.toString(), "NamespaceA.Foo", "Classes pick up their parent namespace");
@@ -35,3 +41,10 @@ test("Classes under Ember.Namespace are properly named", function() {
nsB.Foo = Ember.Object.extend();
equal(nsB.Foo.toString(), "NamespaceB.Foo", "Classes in new namespaces get the naming treatment");
});
+
+test("Classes under Ember are properly named", function() {
+ equal(Ember.Array.toString(), "Ember.Array", "precond - existing classes are processed");
+
+ Ember.TestObject = Ember.Object.extend({});
+ equal(Ember.TestObject.toString(), "Ember.TestObject", "class under Ember is given a string representation");
+}); | true |
Other | emberjs | ember.js | 7429f461cb8b5ee82b12efefe5e15f936b25ff97.json | Add a currentView property to StateManager | packages/ember-states/lib/state_manager.js | @@ -40,6 +40,27 @@ Ember.StateManager = Ember.State.extend({
currentState: null,
+ /**
+ If the current state is a view state or the descendent of a view state,
+ this property will be the view associated with it. If there is no
+ view state active in this state manager, this value will be null.
+ */
+ currentView: SC.computed(function() {
+ var currentState = get(this, 'currentState'),
+ view;
+
+ while (currentState) {
+ if (get(currentState, 'isViewState')) {
+ view = get(currentState, 'view');
+ if (view) { return view; }
+ }
+
+ currentState = get(currentState, 'parentState')
+ }
+
+ return null;
+ }).property('currentState').cacheable(),
+
send: function(event, context) {
this.sendRecursively(event, get(this, 'currentState'), context);
}, | true |
Other | emberjs | ember.js | 7429f461cb8b5ee82b12efefe5e15f936b25ff97.json | Add a currentView property to StateManager | packages/ember-states/tests/state_manager_test.js | @@ -177,6 +177,21 @@ test("it automatically transitions to a default state specified using the initia
ok(get(stateManager, 'currentState').isStart, "automatically transitions to beginning state");
});
+test("it reports the view associated with the current view state, if any", function() {
+ var view = SC.View.create();
+
+ stateManager = SC.StateManager.create({
+ foo: SC.ViewState.create({
+ view: view,
+ bar: SC.State.create()
+ })
+ });
+
+ stateManager.goToState('foo.bar');
+
+ equal(get(stateManager, 'currentView'), view, "returns nearest parent view state's view");
+});
+
module("Ember.StateManager - Transitions on Complex State Managers");
/** | true |
Other | emberjs | ember.js | 8618e230995193a740277b53ae3edbcc24702a37.json | Fix mistake made in renamespacing | README.md | @@ -21,7 +21,7 @@ MyApp.president = Ember.Object.create({
name: "Barack Obama"
});
-MyApp.country = Ember({
+MyApp.country = Ember.Object.create({
// Ending a property with 'Binding' tells Ember.js to
// create a binding to the presidentName property.
presidentNameBinding: 'MyApp.president.name' | false |
Other | emberjs | ember.js | fdb4ae03401c353113c550967a29b53e259e63ee.json | Add license file | LICENSE | @@ -0,0 +1,19 @@
+Copyright (c) 2011 Yehuda Katz, Tom Dale, Charles Jolley and Ember.js contributors
+
+Permission is hereby granted, free of charge, to any person obtaining a copy of
+this software and associated documentation files (the "Software"), to deal in
+the Software without restriction, including without limitation the rights to
+use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
+of the Software, and to permit persons to whom the Software is furnished to do
+so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in all
+copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+SOFTWARE. | false |
Other | emberjs | ember.js | e00a8befb352caefe3af41a6ff1f41b3132abf4e.json | Update Rakefile to build Ember.js | Rakefile | @@ -3,12 +3,13 @@ abort "Please use Ruby 1.9 to build Amber.js!" if RUBY_VERSION !~ /^1\.9/
require "bundler/setup"
require "erb"
require "uglifier"
+
+# for now, the SproutCore compiler will be used to compile Ember.js
require "sproutcore"
LICENSE = File.read("generators/license.js")
-## Some SproutCore modules expect an exports object to exist. Until bpm exists,
-## just mock this out for now.
+## Some Ember modules expect an exports object to exist. Mock it out.
module SproutCore
module Compiler
@@ -44,19 +45,19 @@ end
SproutCore::Compiler.intermediate = "tmp/intermediate"
SproutCore::Compiler.output = "tmp/static"
-# Create a compile task for a SproutCore package. This task will compute
+# Create a compile task for an Ember package. This task will compute
# dependencies and output a single JS file for a package.
-def compile_package_task(package)
- js_tasks = SproutCore::Compiler::Preprocessors::JavaScriptTask.with_input "packages/#{package}/lib/**/*.js", "."
- SproutCore::Compiler::CombineTask.with_tasks js_tasks, "#{SproutCore::Compiler.intermediate}/#{package}"
+def compile_package_task(input, output=input)
+ js_tasks = SproutCore::Compiler::Preprocessors::JavaScriptTask.with_input "packages/#{input}/lib/**/*.js", "."
+ SproutCore::Compiler::CombineTask.with_tasks js_tasks, "#{SproutCore::Compiler.intermediate}/#{output}"
end
## TASKS ##
-# Create sproutcore:package tasks for each of the SproutCore packages
-namespace :sproutcore do
+# Create ember:package tasks for each of the Ember packages
+namespace :ember do
%w(metal runtime handlebars views states).each do |package|
- task package => compile_package_task("sproutcore-#{package}")
+ task package => compile_package_task("sproutcore-#{package}", "ember-#{package}")
end
end
@@ -67,54 +68,54 @@ task :handlebars => compile_package_task("handlebars")
task :metamorph => compile_package_task("metamorph")
# Create a build task that depends on all of the package dependencies
-task :build => ["sproutcore:metal", "sproutcore:runtime", "sproutcore:handlebars", "sproutcore:views", "sproutcore:states", :handlebars, :metamorph]
+task :build => ["ember:metal", "ember:runtime", "ember:handlebars", "ember:views", "ember:states", :handlebars, :metamorph]
-# Strip out require lines from sproutcore.js. For the interim, requires are
+# Strip out require lines from ember.js. For the interim, requires are
# precomputed by the compiler so they are no longer necessary at runtime.
-file "dist/sproutcore.js" => :build do
- puts "Generating sproutcore.js"
+file "dist/ember.js" => :build do
+ puts "Generating ember.js"
mkdir_p "dist"
- File.open("dist/sproutcore.js", "w") do |file|
+ File.open("dist/ember.js", "w") do |file|
file.puts strip_require("tmp/static/handlebars.js")
- file.puts strip_require("tmp/static/sproutcore-metal.js")
- file.puts strip_require("tmp/static/sproutcore-runtime.js")
- file.puts strip_require("tmp/static/sproutcore-views.js")
- file.puts strip_require("tmp/static/sproutcore-states.js")
+ file.puts strip_require("tmp/static/ember-metal.js")
+ file.puts strip_require("tmp/static/ember-runtime.js")
+ file.puts strip_require("tmp/static/ember-views.js")
+ file.puts strip_require("tmp/static/ember-states.js")
file.puts strip_require("tmp/static/metamorph.js")
- file.puts strip_require("tmp/static/sproutcore-handlebars.js")
+ file.puts strip_require("tmp/static/ember-handlebars.js")
end
end
-# Minify dist/sproutcore.js to dist/sproutcore.min.js
-file "dist/sproutcore.min.js" => "dist/sproutcore.js" do
- puts "Generating sproutcore.min.js"
+# Minify dist/ember.js to dist/ember.min.js
+file "dist/ember.min.js" => "dist/ember.js" do
+ puts "Generating ember.min.js"
- File.open("dist/sproutcore.prod.js", "w") do |file|
- file.puts strip_sc_assert("dist/sproutcore.js")
+ File.open("dist/ember.prod.js", "w") do |file|
+ file.puts strip_sc_assert("dist/ember.js")
end
- File.open("dist/sproutcore.min.js", "w") do |file|
- file.puts uglify("dist/sproutcore.prod.js")
+ File.open("dist/ember.min.js", "w") do |file|
+ file.puts uglify("dist/ember.prod.js")
end
- rm "dist/sproutcore.prod.js"
+ rm "dist/ember.prod.js"
end
-SC_VERSION = File.read("VERSION")
+SC_VERSION = File.read("VERSION").strip
desc "bump the version to the specified version"
task :bump_version, :version do |t, args|
version = args[:version]
File.open("VERSION", "w") { |file| file.write version }
- # Bump the version of subcomponents required by the "umbrella" sproutcore
+ # Bump the version of subcomponents required by the "umbrella" ember
# package.
- contents = File.read("packages/sproutcore/package.json")
- contents.gsub! %r{"sproutcore-(\w+)": .*$} do
- %{"sproutcore-#{$1}": "#{version}"}
+ contents = File.read("packages/ember/package.json")
+ contents.gsub! %r{"ember-(\w+)": .*$} do
+ %{"ember-#{$1}": "#{version}"}
end
File.open("packages/sproutcore/package.json", "w") do |file|
@@ -139,8 +140,8 @@ end
## STARTER KIT ##
namespace :starter_kit do
- sproutcore_output = "tmp/starter-kit/js/libs/sproutcore-#{SC_VERSION}.js"
- sproutcore_min_output = "tmp/starter-kit/js/libs/sproutcore-#{SC_VERSION}.min.js"
+ ember_output = "tmp/starter-kit/js/libs/ember-#{SC_VERSION}.js"
+ ember_min_output = "tmp/starter-kit/js/libs/ember-#{SC_VERSION}.min.js"
task :pull => "tmp/starter-kit" do
Dir.chdir("tmp/starter-kit") do
@@ -150,7 +151,7 @@ namespace :starter_kit do
task :clean => :pull do
Dir.chdir("tmp/starter-kit") do
- rm_rf Dir["js/libs/sproutcore*.js"]
+ rm_rf Dir["js/libs/ember*.js"]
end
end
@@ -162,38 +163,38 @@ namespace :starter_kit do
end
end
- file sproutcore_output => [:clean, "tmp/starter-kit", "dist/sproutcore.js"] do
- sh "cp dist/sproutcore.js #{sproutcore_output}"
+ file ember_output => [:clean, "tmp/starter-kit", "dist/ember.js"] do
+ sh "cp dist/ember.js #{ember_output}"
end
- file sproutcore_min_output => [:clean, "tmp/starter-kit", "dist/sproutcore.min.js"] do
- sh "cp dist/sproutcore.min.js #{sproutcore_min_output}"
+ file ember_min_output => [:clean, "tmp/starter-kit", "dist/ember.min.js"] do
+ sh "cp dist/ember.min.js #{ember_min_output}"
end
file "tmp/starter-kit" do
mkdir_p "tmp"
Dir.chdir("tmp") do
- sh "git clone git://github.com/sproutcore/starter-kit.git"
+ sh "git clone git://github.com/emberjs/starter-kit.git"
end
end
- file "tmp/starter-kit/index.html" => [sproutcore_output, sproutcore_min_output] do
+ file "tmp/starter-kit/index.html" => [ember_output, ember_min_output] do
index = File.read("tmp/starter-kit/index.html")
- index.gsub! %r{<script src="js/libs/sproutcore-\d\.\d.*</script>},
- %{<script src="js/libs/sproutcore-#{SC_VERSION}.min.js"></script>}
+ index.gsub! %r{<script src="js/libs/ember-\d\.\d.*</script>},
+ %{<script src="js/libs/ember-#{SC_VERSION}.min.js"></script>}
File.open("tmp/starter-kit/index.html", "w") { |f| f.write index }
end
task :index => "tmp/starter-kit/index.html"
- desc "Build the SproutCore starter kit"
+ desc "Build the Ember.js starter kit"
task :build => "dist/starter-kit.#{SC_VERSION}.zip"
end
-desc "Build SproutCore"
-task :dist => ["dist/sproutcore.min.js"]
+desc "Build Ember.js"
+task :dist => ["dist/ember.min.js"]
desc "Clean build artifacts from previous builds"
task :clean do | false |
Other | emberjs | ember.js | ba51f13c92ad66aab422a57e03d7499e47bcda29.json | Add Ember namespaces | packages/sproutcore-metal/lib/core.js | @@ -30,7 +30,7 @@ SC = {};
// aliases needed to keep minifiers from removing the global context
if ('undefined' !== typeof window) {
- window.SC = window.SproutCore = SproutCore = SC;
+ window.Em = window.Ember = window.SC = window.SproutCore = Em = Ember = SproutCore = SC;
}
} | false |
Other | emberjs | ember.js | e283a95ab5c629ed9cc4c15d9ffda92006d4bfd5.json | Add missing var | packages/sproutcore-views/lib/views/view.js | @@ -487,7 +487,7 @@ SC.View = SC.Object.extend(
// Normalize property path to be suitable for use
// as a class name. For exaple, content.foo.barBaz
// becomes bar-baz.
- parts = property.split('.');
+ var parts = property.split('.');
return SC.String.dasherize(parts[parts.length-1]);
// If the value is not NO, undefined, or null, return the current | false |
Other | emberjs | ember.js | c3802f16380843b39c8363cda68d8813a3e00cdf.json | Allow aliasing of classNameBindings from templates | packages/sproutcore-handlebars/lib/helpers/binding.js | @@ -304,11 +304,16 @@ SC.Handlebars.bindClasses = function(context, classBindings, view, id) {
// determine which class string to return, based on whether it is
// a Boolean or not.
var classStringForProperty = function(property) {
+ var split = property.split(':'), className = split[1];
+ property = split[0];
+
var val = getPath(context, property);
// If value is a Boolean and true, return the dasherized property
// name.
if (val === YES) {
+ if (className) { return className; }
+
// Normalize property path to be suitable for use
// as a class name. For exaple, content.foo.barBaz
// becomes bar-baz.
@@ -329,7 +334,7 @@ SC.Handlebars.bindClasses = function(context, classBindings, view, id) {
// For each property passed, loop through and setup
// an observer.
- classBindings.split(' ').forEach(function(property) {
+ classBindings.split(' ').forEach(function(binding) {
// Variable in which the old class value is saved. The observer function
// closes over this variable, so it knows which string to remove when
@@ -342,13 +347,13 @@ SC.Handlebars.bindClasses = function(context, classBindings, view, id) {
// class name.
observer = function() {
// Get the current value of the property
- newClass = classStringForProperty(property);
+ newClass = classStringForProperty(binding);
elem = id ? view.$("[data-handlebars-id='" + id + "']") : view.$();
// If we can't find the element anymore, a parent template has been
// re-rendered and we've been nuked. Remove the observer.
if (elem.length === 0) {
- SC.removeObserver(context, property, invoker);
+ SC.removeObserver(context, binding, invoker);
} else {
// If we had previously added a class to the element, remove it.
if (oldClass) {
@@ -370,11 +375,12 @@ SC.Handlebars.bindClasses = function(context, classBindings, view, id) {
SC.run.once(observer);
};
+ property = binding.split(':')[0];
SC.addObserver(context, property, invoker);
// We've already setup the observer; now we just need to figure out the
// correct behavior right now on the first pass through.
- value = classStringForProperty(property);
+ value = classStringForProperty(binding);
if (value) {
ret.push(value); | true |
Other | emberjs | ember.js | c3802f16380843b39c8363cda68d8813a3e00cdf.json | Allow aliasing of classNameBindings from templates | packages/sproutcore-handlebars/tests/handlebars_test.js | @@ -1136,10 +1136,11 @@ test("should be able to bind boolean element attributes using {{bindAttr}}", fun
});
test("should be able to add multiple classes using {{bindAttr class}}", function() {
- var template = SC.Handlebars.compile('<div {{bindAttr class="content.isAwesomeSauce content.isAlsoCool"}}></div>');
+ var template = SC.Handlebars.compile('<div {{bindAttr class="content.isAwesomeSauce content.isAlsoCool content.isAmazing:amazing"}}></div>');
var content = SC.Object.create({
isAwesomeSauce: true,
- isAlsoCool: true
+ isAlsoCool: true,
+ isAmazing: true
});
view = SC.View.create({
@@ -1151,12 +1152,15 @@ test("should be able to add multiple classes using {{bindAttr class}}", function
ok(view.$('div').hasClass('is-awesome-sauce'), "dasherizes first property and sets classname");
ok(view.$('div').hasClass('is-also-cool'), "dasherizes second property and sets classname");
+ ok(view.$('div').hasClass('amazing'), "uses alias for third property and sets classname");
SC.run(function() {
set(content, 'isAwesomeSauce', false);
+ set(content, 'isAmazing', false);
});
ok(!view.$('div').hasClass('is-awesome-sauce'), "removes dasherized class when property is set to false");
+ ok(!view.$('div').hasClass('amazing'), "removes aliased class when property is set to false");
});
test("should be able to output a property without binding", function(){ | true |
Other | emberjs | ember.js | 318ad59c2a738688826b12c7de48be13b5342fe5.json | Use charAt for IE7 support | packages/sproutcore-metal/lib/accessors.js | @@ -158,7 +158,7 @@ function getPath(target, path) {
var len = path.length, idx, next, key;
idx = path.indexOf('*');
- if (idx>0 && path[idx-1]!=='.') {
+ if (idx>0 && path.charAt(idx-1)!=='.') {
return getPath(getPath(target, path.slice(0, idx)), path.slice(idx+1));
}
| false |
Other | emberjs | ember.js | 0aa19c52977f06b64f40d2821378b4dcf1969a0e.json | Require Ruby 1.9 to build. | Rakefile | @@ -1,3 +1,5 @@
+abort "Please use Ruby 1.9 to build Amber.js!" if RUBY_VERSION !~ /^1\.9/
+
require "bundler/setup"
require "erb"
require "uglifier" | false |
Other | emberjs | ember.js | 194bfa2bc060a24c64b0377a62508c089cc735c8.json | Change the name and some elementary bits. | README.md | @@ -1,16 +1,18 @@
-# SproutCore
+# Amber.js
-SproutCore is a JavaScript framework that does all of the heavy lifting that you'd normally have to do by hand. There are tasks that are common to every web app; SproutCore does those things for you, so you can focus on building killer features and UI.
+Amber.js (formerly SproutCore 2.0) is a JavaScript framework that does all of the heavy lifting that you'd normally have to do by hand. There are tasks that are common to every web app; Amber.js does those things for you, so you can focus on building killer features and UI.
-These are the three features that make SproutCore a joy to use:
+These are the three features that make Amber.js a joy to use:
1. Bindings
2. Computed properties
3. Auto-updating templates
+Amber.js has strong roots in SproutCore; you can read more about its evolution in [the Amber.js launch announcement](http://yehudakatz.com/2011/12/08/announcing-amber-js/).
+
## Bindings
-Use bindings to keep properties between two different objects in sync. You just declare a binding once, and SproutCore will make sure changes get propagated in either direction.
+Use bindings to keep properties between two different objects in sync. You just declare a binding once, and Amber.js will make sure changes get propagated in either direction.
Here's how you create a binding between two objects:
@@ -79,19 +81,19 @@ Hopefully you can see how all three of these powerful tools work together: start
# Getting Started
-For new users, we recommend downloading the [SproutCore Starter Kit](https://github.com/sproutcore/starter-kit/downloads), which includes everything you need to get started.
+For new users, we recommend downloading the [Amber.js Starter Kit](https://github.com/amberjs/starter-kit/downloads), which includes everything you need to get started.
-We also recommend that you check out the [annotated Todos example](http://annotated-todos.strobeapp.com/), which shows you the best practices for architecting an MVC-based web application.
+We also recommend that you check out the [annotated Todos example](http://annotated-todos.strobeapp.com/), which shows you the best practices for architecting an MVC-based web application. You can also [browse or fork the code on Github](https://github.com/amberjs/todos).
The [SproutCore Guides are available](http://guides.sproutcore20.com/) for SproutCore 2.0. If you find an error, please [fork the guides on GitHub](https://github.com/sproutcore/sproutguides/tree/v2.0) and submit a pull request. (Note that 2.0 guides are on the `v2.0` branch.)
To learn more about what we're up to, follow [@sproutcore on Twitter](http://twitter.com/sproutcore), [subscribe to the blog](http://blog.sproutcore.com), or [read the original SproutCore 2.0 announcement](http://blog.sproutcore.com/announcing-sproutcore-2-0/).
-# Building SproutCore 2.0
+# Building Amber.js
-1. Run `rake` to build SproutCore. Two builds will be placed in the `dist/` directory.
- * `sproutcore.js` and `sproutcore.min.js` - unminified and minified
- builds of SproutCore 2.0
+1. Run `rake` to build Amber.js. Two builds will be placed in the `dist/` directory.
+ * `amber.js` and `amber.min.js` - unminified and minified
+ builds of Amber.js
If you are building under Linux, you will need a JavaScript runtime for
minification. You can either install nodejs or `gem install
@@ -108,9 +110,9 @@ therubyracer`.
5. Then visit: `http://localhost:4020/assets/spade-qunit/index.html?package=PACKAGE_NAME`. Replace `PACKAGE_NAME` with the name of the package you want to run. For example:
- * [SproutCore Runtime](http://localhost:4020/assets/spade-qunit/index.html?package=sproutcore-runtime)
- * [SproutCore Views](http://localhost:4020/assets/spade-qunit/index.html?package=sproutcore-views)
- * [SproutCore Handlebars](http://localhost:4020/assets/spade-qunit/index.html?package=sproutcore-handlebars)
+ * [Amber.js Runtime](http://localhost:4020/assets/spade-qunit/index.html?package=sproutcore-runtime)
+ * [Amber.js Views](http://localhost:4020/assets/spade-qunit/index.html?package=sproutcore-views)
+ * [Amber.js Handlebars](http://localhost:4020/assets/spade-qunit/index.html?package=sproutcore-handlebars)
To run multiple packages, you can separate them with commas. For
example, to run all of the unit tests together: | false |
Other | emberjs | ember.js | 3ef01860e0274bf782ac714b8b8313fa1832f9b5.json | Add sproutcore-states to Rakefile | Rakefile | @@ -53,7 +53,7 @@ end
# Create sproutcore:package tasks for each of the SproutCore packages
namespace :sproutcore do
- %w(metal runtime handlebars views).each do |package|
+ %w(metal runtime handlebars views states).each do |package|
task package => compile_package_task("sproutcore-#{package}")
end
end
@@ -65,7 +65,7 @@ task :handlebars => compile_package_task("handlebars")
task :metamorph => compile_package_task("metamorph")
# Create a build task that depends on all of the package dependencies
-task :build => ["sproutcore:metal", "sproutcore:runtime", "sproutcore:handlebars", "sproutcore:views", :handlebars, :metamorph]
+task :build => ["sproutcore:metal", "sproutcore:runtime", "sproutcore:handlebars", "sproutcore:views", "sproutcore:states", :handlebars, :metamorph]
# Strip out require lines from sproutcore.js. For the interim, requires are
# precomputed by the compiler so they are no longer necessary at runtime.
@@ -79,6 +79,7 @@ file "dist/sproutcore.js" => :build do
file.puts strip_require("tmp/static/sproutcore-metal.js")
file.puts strip_require("tmp/static/sproutcore-runtime.js")
file.puts strip_require("tmp/static/sproutcore-views.js")
+ file.puts strip_require("tmp/static/sproutcore-states.js")
file.puts strip_require("tmp/static/metamorph.js")
file.puts strip_require("tmp/static/sproutcore-handlebars.js")
end | false |
Other | emberjs | ember.js | f701bff1e4eb52112e7b125f034e1bb68acdb6d8.json | Update Metamorph to latest version. | packages/metamorph/lib/main.js | @@ -7,6 +7,7 @@
var K = function(){},
guid = 0,
+ document = window.document,
// Feature-detect the W3C range API
supportsRange = ('createRange' in document);
@@ -22,7 +23,7 @@
if (this instanceof Metamorph) {
self = this;
} else {
- self = new K;
+ self = new K();
}
self.innerHTML = html;
@@ -129,7 +130,7 @@
*
* We need to do this because innerHTML in IE does not really parse the nodes.
**/
- function firstNodeFor(parentNode, html) {
+ var firstNodeFor = function(parentNode, html) {
var arr = wrapMap[parentNode.tagName.toLowerCase()] || wrapMap._default;
var depth = arr[0], start = arr[1], end = arr[2];
@@ -141,7 +142,7 @@
}
return element;
- }
+ };
/**
* Internet Explorer does not allow setting innerHTML if the first element
@@ -166,7 +167,7 @@
* node and use *it* as the marker.
**/
var realNode = function(start) {
- while (start.parentNode.tagName == "") {
+ while (start.parentNode.tagName === "") {
start = start.parentNode;
}
@@ -223,6 +224,7 @@
// remove all of the nodes after the starting placeholder and
// before the ending placeholder.
+ node = start.nextSibling;
while (node) {
nextSibling = node.nextSibling;
last = node === end; | false |
Other | emberjs | ember.js | 0c632a6be3440c8f941f271921765ba35083528d.json | Use SC.get instead of this.get | packages/sproutcore-handlebars/lib/controls/button.js | @@ -22,7 +22,7 @@ SC.Button = SC.View.extend(SC.TargetActionSupport, {
set(this, 'isActive', true);
this._mouseDown = true;
this._mouseEntered = true;
- return this.get('propagateEvents');
+ return get(this, 'propagateEvents');
},
mouseLeave: function() {
@@ -50,7 +50,7 @@ SC.Button = SC.View.extend(SC.TargetActionSupport, {
this._mouseDown = false;
this._mouseEntered = false;
- return this.get('propagateEvents');
+ return get(this, 'propagateEvents');
},
// TODO: Handle proper touch behavior. Including should make inactive when | false |
Other | emberjs | ember.js | 86f5f87b06d4786f90c6e3c5bb5725f1b38654c0.json | Remove overriding removeObserver on bind views.
I have no idea what this does and it seems crazy. | packages/sproutcore-handlebars/lib/helpers/binding.js | @@ -54,10 +54,6 @@ var get = SC.get, getPath = SC.getPath, set = SC.set, fmt = SC.String.fmt;
// is an empty string, we are printing the current context
// object ({{this}}) so updating it is not our responsibility.
if (property !== '') {
- set(bindView, 'removeObserver', function() {
- SC.removeObserver(ctx, property, invoker);
- });
-
SC.addObserver(ctx, property, invoker);
}
} else { | false |
Other | emberjs | ember.js | 0eae4c91d196b97decb34be66cd45d08d3fa8a44.json | Improve performance of namespace stringification.
New heuristic:
* after a namespace is added for the first time, scan for it and give it a name
* after that, only scan namespaces for new classes
A possible further improvement: preemptively process classes at the end of the
run loop following their creation. There still may be some cases where scanning
is necessary, but this should significantly increase the likelihood that the
first attempt to call toString on a class is covered. | packages/sproutcore-metal/lib/mixin.js | @@ -395,6 +395,24 @@ function processNames(paths, root, seen) {
paths.length = idx; // cut out last item
}
+function findNamespaces() {
+ var Namespace = SC.Namespace, obj;
+
+ if (Namespace.PROCESSED) { return; }
+
+ for (var prop in window) {
+ if (!window.hasOwnProperty(prop)) { continue; }
+
+ obj = window[prop];
+
+ if (obj instanceof Namespace) {
+ obj[NAME_KEY] = prop;
+ }
+ }
+}
+
+SC.identifyNamespaces = findNamespaces;
+
superClassString = function(mixin) {
var superclass = mixin.superclass;
if (superclass) {
@@ -406,9 +424,24 @@ superClassString = function(mixin) {
}
classToString = function() {
- if (!this[NAME_KEY] && !classToString.processed) {
- classToString.processed = true;
- processNames([], window, {});
+ var Namespace = SC.Namespace, namespace;
+
+ // TODO: Namespace should really be in Metal
+ if (Namespace) {
+ if (!this[NAME_KEY] && !classToString.processed) {
+ if (!Namespace.PROCESSED) {
+ findNamespaces();
+ Namespace.PROCESSED = true;
+ }
+
+ classToString.processed = true;
+
+ var namespaces = Namespace.NAMESPACES;
+ for (var i=0, l=namespaces.length; i<l; i++) {
+ namespace = namespaces[i];
+ processNames([namespace.toString()], namespace, {});
+ }
+ }
}
if (this[NAME_KEY]) {
@@ -421,8 +454,6 @@ classToString = function() {
return "(unknown mixin)";
}
}
-
- return this[NAME_KEY] || "(unknown mixin)";
};
Mixin.prototype.toString = classToString; | true |
Other | emberjs | ember.js | 0eae4c91d196b97decb34be66cd45d08d3fa8a44.json | Improve performance of namespace stringification.
New heuristic:
* after a namespace is added for the first time, scan for it and give it a name
* after that, only scan namespaces for new classes
A possible further improvement: preemptively process classes at the end of the
run loop following their creation. There still may be some cases where scanning
is necessary, but this should significantly increase the likelihood that the
first attempt to call toString on a class is covered. | packages/sproutcore-runtime/lib/system/namespace.js | @@ -8,15 +8,35 @@ require('sproutcore-runtime/system/object');
/**
@private
- A Namespace is an object usually used to contain other objects or methods
+ A Namespace is an object usually used to contain other objects or methods
such as an application or framework. Create a namespace anytime you want
to define one of these new containers.
-
+
# Example Usage
-
+
MyFramework = SC.Namespace.create({
VERSION: '1.0.0'
});
-
+
*/
-SC.Namespace = SC.Object.extend();
+SC.Namespace = SC.Object.extend({
+ init: function() {
+ SC.Namespace.NAMESPACES.push(this);
+ SC.Namespace.PROCESSED = false;
+ },
+
+ toString: function() {
+ SC.identifyNamespaces();
+ return this[SC.GUID_KEY+'_name'];
+ },
+
+ destroy: function() {
+ var namespaces = SC.Namespace.NAMESPACES;
+ window[this.toString()] = undefined;
+ namespaces.splice(namespaces.indexOf(this), 1);
+ this._super();
+ }
+});
+
+SC.Namespace.NAMESPACES = [];
+SC.Namespace.PROCESSED = true; | true |
Other | emberjs | ember.js | 0eae4c91d196b97decb34be66cd45d08d3fa8a44.json | Improve performance of namespace stringification.
New heuristic:
* after a namespace is added for the first time, scan for it and give it a name
* after that, only scan namespaces for new classes
A possible further improvement: preemptively process classes at the end of the
run loop following their creation. There still may be some cases where scanning
is necessary, but this should significantly increase the likelihood that the
first attempt to call toString on a class is covered. | packages/sproutcore-runtime/tests/system/namespace/base_test.js | @@ -4,8 +4,34 @@
// License: Licensed under MIT license (see license.js)
// ==========================================================================
-module('SC.Namepsace');
+module('SC.Namespace', {
+ teardown: function() {
+ if (window.NamespaceA) { window.NamespaceA.destroy(); }
+ if (window.NamespaceB) { window.NamespaceB.destroy(); }
+ }
+});
test('SC.Namespace should be a subclass of SC.Object', function() {
ok(SC.Object.detect(SC.Namespace));
});
+
+test('SC.Namespace is found and named', function() {
+ var nsA = window.NamespaceA = SC.Namespace.create();
+ equal(nsA.toString(), "NamespaceA", "namespaces should have a name if they are on window");
+
+ var nsB = window.NamespaceB = SC.Namespace.create();
+ equal(nsB.toString(), "NamespaceB", "namespaces work if created after the first namespace processing pass");
+});
+
+test("Classes under SC.Namespace are properly named", function() {
+ var nsA = window.NamespaceA = SC.Namespace.create();
+ nsA.Foo = SC.Object.extend();
+ equal(nsA.Foo.toString(), "NamespaceA.Foo", "Classes pick up their parent namespace");
+
+ nsA.Bar = SC.Object.extend();
+ equal(nsA.Bar.toString(), "NamespaceA.Bar", "New Classes get the naming treatment too");
+
+ var nsB = window.NamespaceB = SC.Namespace.create();
+ nsB.Foo = SC.Object.extend();
+ equal(nsB.Foo.toString(), "NamespaceB.Foo", "Classes in new namespaces get the naming treatment");
+}); | true |
Other | emberjs | ember.js | 0eae4c91d196b97decb34be66cd45d08d3fa8a44.json | Improve performance of namespace stringification.
New heuristic:
* after a namespace is added for the first time, scan for it and give it a name
* after that, only scan namespaces for new classes
A possible further improvement: preemptively process classes at the end of the
run loop following their creation. There still may be some cases where scanning
is necessary, but this should significantly increase the likelihood that the
first attempt to call toString on a class is covered. | packages/sproutcore-views/tests/views/view/attribute_bindings_test.js | @@ -93,6 +93,6 @@ test("should allow attributes to be set in the inBuffer state", function() {
equals(parentView.get('childViews')[0].$().attr('foo'), 'baz');
parentView.destroy();
-
+ Test.destroy();
});
| true |
Other | emberjs | ember.js | 6c6b8f9b21b79c69f6c19ff2f27ac57db72f38b8.json | Fix EXTEND_PROTOTYPES for sproutcore-handlebars | packages/sproutcore-handlebars/lib/helpers/binding.js | @@ -316,7 +316,8 @@ SC.Handlebars.bindClasses = function(context, classBindings, view, id) {
// Normalize property path to be suitable for use
// as a class name. For exaple, content.foo.barBaz
// becomes bar-baz.
- return SC.String.dasherize(get(property.split('.'), 'lastObject'));
+ var parts = property.split('.');
+ return SC.String.dasherize(parts[parts.length-1]);
// If the value is not NO, undefined, or null, return the current
// value of the property. | true |
Other | emberjs | ember.js | 6c6b8f9b21b79c69f6c19ff2f27ac57db72f38b8.json | Fix EXTEND_PROTOTYPES for sproutcore-handlebars | packages/sproutcore-handlebars/lib/helpers/collection.js | @@ -9,7 +9,7 @@
require('sproutcore-handlebars');
require('sproutcore-handlebars/helpers/view');
-var get = SC.get;
+var get = SC.get, fmt = SC.String.fmt;
/**
@name Handlebars.helpers.collection
@@ -35,7 +35,7 @@ SC.Handlebars.registerHelper('collection', function(path, options) {
// Otherwise, just default to the standard class.
var collectionClass;
collectionClass = path ? SC.getPath(this, path) : SC.CollectionView;
- sc_assert("%@ #collection: Could not find %@".fmt(data.view, path), !!collectionClass);
+ sc_assert(fmt("%@ #collection: Could not find %@", data.view, path), !!collectionClass);
var hash = options.hash, itemHash = {}, match;
@@ -44,7 +44,7 @@ SC.Handlebars.registerHelper('collection', function(path, options) {
var collectionPrototype = get(collectionClass, 'proto');
delete hash.itemViewClass;
itemViewClass = itemViewPath ? SC.getPath(collectionPrototype, itemViewPath) : collectionPrototype.itemViewClass;
- sc_assert("%@ #collection: Could not find %@".fmt(data.view, itemViewPath), !!itemViewClass);
+ sc_assert(fmt("%@ #collection: Could not find %@", data.view, itemViewPath), !!itemViewClass);
// Go through options passed to the {{collection}} helper and extract options
// that configure item views instead of the collection itself. | true |
Other | emberjs | ember.js | 6c6b8f9b21b79c69f6c19ff2f27ac57db72f38b8.json | Fix EXTEND_PROTOTYPES for sproutcore-handlebars | packages/sproutcore-handlebars/tests/each_test.js | @@ -47,7 +47,7 @@ test("it updates the view if an item is added", function() {
test("it allows you to access the current context using {{this}}", function() {
view = SC.View.create({
template: templateFor("{{#each people}}{{this}}{{/each}}"),
- people: ['Black Francis', 'Joey Santiago', 'Kim Deal', 'David Lovering']
+ people: SC.NativeArray.apply(['Black Francis', 'Joey Santiago', 'Kim Deal', 'David Lovering'])
});
append(view); | true |
Other | emberjs | ember.js | 6c6b8f9b21b79c69f6c19ff2f27ac57db72f38b8.json | Fix EXTEND_PROTOTYPES for sproutcore-handlebars | packages/sproutcore-handlebars/tests/handlebars_test.js | @@ -561,7 +561,7 @@ test("should update the block when object passed to #if helper changes", functio
set(view, 'inception', val);
});
- equals(view.$('h1').text(), '', "hides block when conditional is '%@'".fmt(val));
+ equals(view.$('h1').text(), '', SC.String.fmt("hides block when conditional is '%@'", String(val)));
SC.run(function() {
set(view, 'inception', true);
@@ -597,7 +597,7 @@ test("should update the block when object passed to #unless helper changes", fun
set(view, 'onDrugs', val);
});
- equals(view.$('h1').text(), 'Eat your vegetables', "renders block when conditional is '%@'; %@".fmt(val, SC.typeOf(val)));
+ equals(view.$('h1').text(), 'Eat your vegetables', SC.String.fmt("renders block when conditional is '%@'; %@", String(val), SC.typeOf(val)));
SC.run(function() {
set(view, 'onDrugs', true);
@@ -636,7 +636,7 @@ test("should update the block when object passed to #if helper changes and an in
set(view, 'inception', val);
});
- equals(view.$('h1').text(), 'BOONG?', "renders alternate if %@".fmt(val));
+ equals(view.$('h1').text(), 'BOONG?', SC.String.fmt("renders alternate if %@", String(val)));
SC.run(function() {
set(view, 'inception', true);
@@ -783,7 +783,7 @@ test("Collection views that specify an example view class have their children be
isCustom: true
}),
- content: ['foo']
+ content: SC.NativeArray.apply(['foo'])
});
var parentView = SC.View.create({
@@ -801,7 +801,7 @@ test("Collection views that specify an example view class have their children be
test("itemViewClass works in the #collection helper", function() {
TemplateTests.ExampleController = SC.ArrayProxy.create({
- content: ['alpha']
+ content: SC.NativeArray.apply(['alpha'])
});
TemplateTests.ExampleItemView = SC.View.extend({
@@ -823,7 +823,7 @@ test("itemViewClass works in the #collection helper", function() {
test("itemViewClass works in the #collection helper relatively", function() {
TemplateTests.ExampleController = SC.ArrayProxy.create({
- content: ['alpha']
+ content: SC.NativeArray.apply(['alpha'])
});
TemplateTests.ExampleItemView = SC.View.extend({
@@ -1306,7 +1306,7 @@ test("the {{this}} helper should not fail on removal", function(){
view = SC.View.create({
template: SC.Handlebars.compile('{{#if show}}{{#each list}}{{this}}{{/each}}{{/if}}'),
show: true,
- list: ['a', 'b', 'c']
+ list: SC.NativeArray.apply(['a', 'b', 'c'])
});
appendView(); | true |
Other | emberjs | ember.js | 6c6b8f9b21b79c69f6c19ff2f27ac57db72f38b8.json | Fix EXTEND_PROTOTYPES for sproutcore-handlebars | packages/sproutcore-handlebars/tests/views/collection_view_test.js | @@ -32,7 +32,7 @@ module("sproutcore-handlebars/tests/views/collection_view_test", {
test("passing a block to the collection helper sets it as the template for example views", function() {
TemplateTests.CollectionTestView = SC.CollectionView.extend({
tagName: 'ul',
- content: ['foo', 'bar', 'baz']
+ content: SC.NativeArray.apply(['foo', 'bar', 'baz'])
});
view = SC.View.create({
@@ -52,7 +52,7 @@ test("collection helper should accept relative paths", function() {
template: SC.Handlebars.compile('{{#collection collection}} <label></label> {{/collection}}'),
collection: SC.CollectionView.extend({
tagName: 'ul',
- content: ['foo', 'bar', 'baz']
+ content: SC.NativeArray.apply(['foo', 'bar', 'baz'])
})
});
@@ -75,7 +75,7 @@ test("empty views should be removed when content is added to the collection (reg
});
App.ListController = SC.ArrayProxy.create({
- content : []
+ content : SC.NativeArray.apply([])
});
view = SC.View.create({
@@ -98,7 +98,7 @@ test("empty views should be removed when content is added to the collection (reg
test("if no content is passed, and no 'else' is specified, nothing is rendered", function() {
TemplateTests.CollectionTestView = SC.CollectionView.extend({
tagName: 'ul',
- content: []
+ content: SC.NativeArray.apply([])
});
view = SC.View.create({
@@ -115,7 +115,7 @@ test("if no content is passed, and no 'else' is specified, nothing is rendered",
test("if no content is passed, and 'else' is specified, the else block is rendered", function() {
TemplateTests.CollectionTestView = SC.CollectionView.extend({
tagName: 'ul',
- content: []
+ content: SC.NativeArray.apply([])
});
view = SC.View.create({
@@ -132,7 +132,7 @@ test("if no content is passed, and 'else' is specified, the else block is render
test("a block passed to a collection helper defaults to the content property of the context", function() {
TemplateTests.CollectionTestView = SC.CollectionView.extend({
tagName: 'ul',
- content: ['foo', 'bar', 'baz']
+ content: SC.NativeArray.apply(['foo', 'bar', 'baz'])
});
view = SC.View.create({
@@ -149,7 +149,7 @@ test("a block passed to a collection helper defaults to the content property of
test("a block passed to a collection helper defaults to the view", function() {
TemplateTests.CollectionTestView = SC.CollectionView.extend({
tagName: 'ul',
- content: ['foo', 'bar', 'baz']
+ content: SC.NativeArray.apply(['foo', 'bar', 'baz'])
});
view = SC.View.create({
@@ -162,15 +162,15 @@ test("a block passed to a collection helper defaults to the view", function() {
equals(view.$('li:has(label:contains("foo")) + li:has(label:contains("bar")) + li:has(label:contains("baz"))').length, 1, 'precond - one aside element is created for each content item');
SC.run(function() {
- set(firstChild(view), 'content', []);
+ set(firstChild(view), 'content', SC.NativeArray.apply([]));
});
equals(view.$('label').length, 0, "all list item views should be removed from DOM");
});
test("should include an id attribute if id is set in the options hash", function() {
TemplateTests.CollectionTestView = SC.CollectionView.extend({
tagName: 'ul',
- content: ['foo', 'bar', 'baz']
+ content: SC.NativeArray.apply(['foo', 'bar', 'baz'])
});
var view = SC.View.create({
@@ -187,7 +187,7 @@ test("should include an id attribute if id is set in the options hash", function
test("should give its item views the class specified by itemClass", function() {
TemplateTests.itemClassTestCollectionView = SC.CollectionView.extend({
tagName: 'ul',
- content: ['foo', 'bar', 'baz']
+ content: SC.NativeArray.apply(['foo', 'bar', 'baz'])
});
var view = SC.View.create({
template: SC.Handlebars.compile('{{#collection "TemplateTests.itemClassTestCollectionView" itemClass="baz"}}foo{{/collection}}')
@@ -203,7 +203,7 @@ test("should give its item views the class specified by itemClass", function() {
test("should give its item views the classBinding specified by itemClassBinding", function() {
TemplateTests.itemClassBindingTestCollectionView = SC.CollectionView.extend({
tagName: 'ul',
- content: [SC.Object.create({ isBaz: false }), SC.Object.create({ isBaz: true }), SC.Object.create({ isBaz: true })]
+ content: SC.NativeArray.apply([SC.Object.create({ isBaz: false }), SC.Object.create({ isBaz: true }), SC.Object.create({ isBaz: true })])
});
var view = SC.View.create({
@@ -230,7 +230,7 @@ test("should give its item views the classBinding specified by itemClassBinding"
});
test("should work inside a bound {{#if}}", function() {
- var testData = [SC.Object.create({ isBaz: false }), SC.Object.create({ isBaz: true }), SC.Object.create({ isBaz: true })];
+ var testData = SC.NativeArray.apply([SC.Object.create({ isBaz: false }), SC.Object.create({ isBaz: true }), SC.Object.create({ isBaz: true })]);
TemplateTests.ifTestCollectionView = SC.CollectionView.extend({
tagName: 'ul',
content: testData
@@ -258,12 +258,14 @@ test("should pass content as context when using {{#each}} helper", function() {
var view = SC.View.create({
template: SC.Handlebars.compile('{{#each releases}}Mac OS X {{version}}: {{name}} {{/each}}'),
- releases: [ { version: '10.7',
+ releases: SC.NativeArray.apply([
+ { version: '10.7',
name: 'Lion' },
{ version: '10.6',
name: 'Snow Leopard' },
{ version: '10.5',
- name: 'Leopard' } ]
+ name: 'Leopard' }
+ ])
});
SC.run(function() { view.appendTo('#qunit-fixture'); });
@@ -274,7 +276,7 @@ test("should pass content as context when using {{#each}} helper", function() {
test("should re-render when the content object changes", function() {
TemplateTests.RerenderTest = SC.CollectionView.extend({
tagName: 'ul',
- content: []
+ content: SC.NativeArray.apply([])
});
var view = SC.View.create({
@@ -286,11 +288,11 @@ test("should re-render when the content object changes", function() {
});
SC.run(function() {
- set(firstChild(view), 'content', ['bing', 'bat', 'bang']);
+ set(firstChild(view), 'content', SC.NativeArray.apply(['bing', 'bat', 'bang']));
});
SC.run(function() {
- set(firstChild(view), 'content', ['ramalamadingdong']);
+ set(firstChild(view), 'content', SC.NativeArray.apply(['ramalamadingdong']));
});
equals(view.$('li').length, 1, "rerenders with correct number of items");
@@ -300,7 +302,7 @@ test("should re-render when the content object changes", function() {
test("select tagName on collection helper automatically sets child tagName to option", function() {
TemplateTests.RerenderTest = SC.CollectionView.extend({
- content: ['foo']
+ content: SC.NativeArray.apply(['foo'])
});
var view = SC.View.create({
@@ -317,7 +319,7 @@ test("select tagName on collection helper automatically sets child tagName to op
test("tagName works in the #collection helper", function() {
TemplateTests.RerenderTest = SC.CollectionView.extend({
- content: ['foo', 'bar']
+ content: SC.NativeArray.apply(['foo', 'bar'])
});
var view = SC.View.create({
@@ -332,7 +334,7 @@ test("tagName works in the #collection helper", function() {
equals(view.$('li').length, 2, "rerenders with correct number of items");
SC.run(function() {
- set(firstChild(view), 'content', ['bing', 'bat', 'bang']);
+ set(firstChild(view), 'content', SC.NativeArray.apply(['bing', 'bat', 'bang']));
});
equals(view.$('li').length, 3, "rerenders with correct number of items");
@@ -343,12 +345,12 @@ test("should render nested collections", function() {
TemplateTests.InnerList = SC.CollectionView.extend({
tagName: 'ul',
- content: ['one','two','three']
+ content: SC.NativeArray.apply(['one','two','three'])
});
TemplateTests.OuterList = SC.CollectionView.extend({
tagName: 'ul',
- content: ['foo']
+ content: SC.NativeArray.apply(['foo'])
});
var view = SC.View.create({
@@ -370,7 +372,7 @@ test("should render multiple, bound nested collections (#68)", function() {
SC.run(function() {
TemplateTests.contentController = SC.ArrayProxy.create({
- content: ['foo','bar']
+ content: SC.NativeArray.apply(['foo','bar'])
});
TemplateTests.InnerList = SC.CollectionView.extend({
@@ -380,7 +382,7 @@ test("should render multiple, bound nested collections (#68)", function() {
TemplateTests.OuterListItem = SC.View.extend({
template: SC.Handlebars.compile('{{#collection TemplateTests.InnerList class="inner"}}{{content}}{{/collection}}{{content}}'),
- innerListContent: function() { return [1,2,3]; }.property().cacheable()
+ innerListContent: function() { return SC.NativeArray.apply([1,2,3]); }.property().cacheable()
});
TemplateTests.OuterList = SC.CollectionView.extend({
@@ -436,7 +438,7 @@ test("should allow view objects to be swapped out without throwing an error (#78
SC.run(function() {
dataset = SC.Object.create({
ready: true,
- items: [1,2,3]
+ items: SC.NativeArray.apply([1,2,3])
});
TemplateTests.datasetController.set('dataset',dataset);
}); | true |
Other | emberjs | ember.js | 5431c3990377ef052eced529f0bce0929a90f439.json | Fix EXTEND_PROTOTYPES for sproutcore-views | packages/sproutcore-views/lib/system/ext.js | @@ -8,4 +8,4 @@
// Add a new named queue for rendering views that happens
// after bindings have synced.
var queues = SC.run.queues;
-queues.insertAt(queues.indexOf('actions')+1, 'render');
+queues.splice(jQuery.inArray('actions', queues)+1, 0, 'render'); | true |
Other | emberjs | ember.js | 5431c3990377ef052eced529f0bce0929a90f439.json | Fix EXTEND_PROTOTYPES for sproutcore-views | packages/sproutcore-views/lib/system/render_buffer.js | @@ -98,10 +98,10 @@ SC._RenderBuffer = SC.Object.extend(
init: function() {
this._super();
- set(this ,'elementClasses', []);
+ set(this ,'elementClasses', SC.NativeArray.apply([]));
set(this, 'elementAttributes', {});
set(this, 'elementStyle', {});
- set(this, 'childBuffers', []);
+ set(this, 'childBuffers', SC.NativeArray.apply([]));
set(this, 'elements', {});
},
| true |
Other | emberjs | ember.js | 5431c3990377ef052eced529f0bce0929a90f439.json | Fix EXTEND_PROTOTYPES for sproutcore-views | packages/sproutcore-views/lib/views/view.js | @@ -13,11 +13,11 @@ var getPath = SC.getPath, meta = SC.meta, fmt = SC.String.fmt;
var childViewsProperty = SC.computed(function() {
var childViews = get(this, '_childViews');
- var ret = [];
+ var ret = SC.NativeArray.apply([]);
childViews.forEach(function(view) {
if (view.isVirtual) {
- ret = ret.concat(get(view, 'childViews'));
+ ret.pushObjects(get(view, 'childViews'));
} else {
ret.push(view);
}
@@ -105,7 +105,7 @@ SC.View = SC.Object.extend(
}
if (!template) {
- throw new SC.Error('%@ - Unable to find template "%@".'.fmt(this, templateName));
+ throw new SC.Error(fmt('%@ - Unable to find template "%@".', this, templateName));
}
}
@@ -165,7 +165,7 @@ SC.View = SC.Object.extend(
*/
childViews: childViewsProperty,
- _childViews: [],
+ _childViews: SC.NativeArray.apply([]),
/**
Return the nearest ancestor that is an instance of the provided
@@ -484,7 +484,8 @@ SC.View = SC.Object.extend(
// Normalize property path to be suitable for use
// as a class name. For exaple, content.foo.barBaz
// becomes bar-baz.
- return SC.String.dasherize(get(property.split('.'), 'lastObject'));
+ parts = property.split('.');
+ return SC.String.dasherize(parts[parts.length-1]);
// If the value is not NO, undefined, or null, return the current
// value of the property.
@@ -1038,13 +1039,13 @@ SC.View = SC.Object.extend(
// SC.RootResponder to dispatch incoming events.
SC.View.views[get(this, 'elementId')] = this;
- var childViews = get(this, '_childViews').slice();
+ var childViews = SC.NativeArray.apply(get(this, '_childViews').slice());
// setup child views. be sure to clone the child views array first
set(this, '_childViews', childViews);
- this.classNameBindings = get(this, 'classNameBindings').slice();
- this.classNames = get(this, 'classNames').slice();
+ this.classNameBindings = SC.NativeArray.apply(get(this, 'classNameBindings').slice());
+ this.classNames = SC.NativeArray.apply(get(this, 'classNames').slice());
this.set('domManager', this.domManagerClass.create({ view: this }));
| true |
Other | emberjs | ember.js | 5431c3990377ef052eced529f0bce0929a90f439.json | Fix EXTEND_PROTOTYPES for sproutcore-views | packages/sproutcore-views/tests/views/collection_test.js | @@ -20,7 +20,7 @@ module("SC.CollectionView", {
test("should render a view for each item in its content array", function() {
view = SC.CollectionView.create({
- content: [1, 2, 3, 4]
+ content: SC.NativeArray.apply([1, 2, 3, 4])
});
SC.run(function() {
@@ -32,7 +32,7 @@ test("should render a view for each item in its content array", function() {
test("should render the emptyView if content array is empty (view class)", function() {
view = SC.CollectionView.create({
tagName: 'del',
- content: [],
+ content: SC.NativeArray.apply([]),
emptyView: SC.View.extend({
tagName: 'kbd',
@@ -52,7 +52,7 @@ test("should render the emptyView if content array is empty (view class)", funct
test("should render the emptyView if content array is empty (view instance)", function() {
view = SC.CollectionView.create({
tagName: 'del',
- content: [],
+ content: SC.NativeArray.apply([]),
emptyView: SC.View.create({
tagName: 'kbd',
@@ -72,7 +72,7 @@ test("should render the emptyView if content array is empty (view instance)", fu
test("should be able to override the tag name of itemViewClass even if tag is in default mapping", function() {
view = SC.CollectionView.create({
tagName: 'del',
- content: ['NEWS GUVNAH'],
+ content: SC.NativeArray.apply(['NEWS GUVNAH']),
itemViewClass: SC.View.extend({
tagName: 'kbd',
@@ -92,7 +92,7 @@ test("should be able to override the tag name of itemViewClass even if tag is in
test("should allow custom item views by setting itemViewClass", function() {
var passedContents = [];
view = SC.CollectionView.create({
- content: ['foo', 'bar', 'baz'],
+ content: SC.NativeArray.apply(['foo', 'bar', 'baz']),
itemViewClass: SC.View.extend({
render: function(buf) {
@@ -114,7 +114,7 @@ test("should allow custom item views by setting itemViewClass", function() {
});
test("should insert a new item in DOM when an item is added to the content array", function() {
- var content = ['foo', 'bar', 'baz'];
+ var content = SC.NativeArray.apply(['foo', 'bar', 'baz']);
view = SC.CollectionView.create({
content: content,
@@ -142,7 +142,7 @@ test("should insert a new item in DOM when an item is added to the content array
});
test("should remove an item from DOM when an item is removed from the content array", function() {
- var content = ['foo', 'bar', 'baz'];
+ var content = SC.NativeArray.apply(['foo', 'bar', 'baz']);
view = SC.CollectionView.create({
content: content,
@@ -167,7 +167,7 @@ test("should remove an item from DOM when an item is removed from the content ar
});
content.forEach(function(item, idx) {
- equals(view.$(':nth-child(%@)'.fmt(idx+1)).text(), item);
+ equals(view.$(SC.String.fmt(':nth-child(%@)', String(idx+1))).text(), item);
});
});
@@ -176,9 +176,9 @@ test("should allow changes to content object before layer is created", function(
content: null
});
- set(view, 'content', []);
- set(view, 'content', [1, 2, 3]);
- set(view, 'content', [1, 2]);
+ set(view, 'content', SC.NativeArray.apply([]));
+ set(view, 'content', SC.NativeArray.apply([1, 2, 3]));
+ set(view, 'content', SC.NativeArray.apply([1, 2]));
SC.run(function() {
view.append();
@@ -189,7 +189,7 @@ test("should allow changes to content object before layer is created", function(
test("should allow changing content property to be null", function() {
view = SC.CollectionView.create({
- content: [1, 2, 3],
+ content: SC.NativeArray.apply([1, 2, 3]),
emptyView: SC.View.extend({
template: function() { return "(empty)"; }
@@ -211,7 +211,7 @@ test("should allow changing content property to be null", function() {
test("should allow items to access to the CollectionView's current index in the content array", function() {
view = SC.CollectionView.create({
- content: ['zero', 'one', 'two'],
+ content: SC.NativeArray.apply(['zero', 'one', 'two']),
itemViewClass: SC.View.extend({
render: function(buf) {
buf.push(get(this, 'contentIndex')); | true |
Other | emberjs | ember.js | 5431c3990377ef052eced529f0bce0929a90f439.json | Fix EXTEND_PROTOTYPES for sproutcore-views | packages/sproutcore-views/tests/views/view/nearest_view_test.js | @@ -12,7 +12,7 @@ test("collectionView should return the nearest collection view", function() {
var itemViewChild;
var view = SC.CollectionView.create({
- content: [1, 2, 3],
+ content: SC.NativeArray.apply([1, 2, 3]),
isARealCollection: true,
itemViewClass: SC.View.extend({
@@ -34,7 +34,7 @@ test("itemView should return the nearest child of a collection view", function()
var itemViewChild;
var view = SC.CollectionView.create({
- content: [1, 2, 3],
+ content: SC.NativeArray.apply([1, 2, 3]),
itemViewClass: SC.View.extend({
isAnItemView: true,
@@ -57,7 +57,7 @@ test("itemView should return the nearest child of a collection view", function()
var itemViewChild;
var view = SC.CollectionView.create({
- content: [1, 2, 3],
+ content: SC.NativeArray.apply([1, 2, 3]),
itemViewClass: SC.View.extend({
isAnItemView: true, | true |
Other | emberjs | ember.js | 1fa9fa630fc31a7310fd838c2ee51ac940464a9d.json | Fix EXTEND_PROTOTYPES for sproutcore-runtime | packages/sproutcore-handlebars/tests/each_test.js | @@ -3,7 +3,7 @@ var people, view;
module("the #each helper", {
setup: function() {
template = templateFor("{{#each people}}{{name}}{{/each}}");
- people = SC.Array.apply([{ name: "Steve Holt" }, { name: "Annabelle" }]);
+ people = SC.NativeArray.apply([{ name: "Steve Holt" }, { name: "Annabelle" }]);
view = SC.View.create({
template: template, | true |
Other | emberjs | ember.js | 1fa9fa630fc31a7310fd838c2ee51ac940464a9d.json | Fix EXTEND_PROTOTYPES for sproutcore-runtime | packages/sproutcore-runtime/tests/controllers/array_controller_test.js | @@ -15,7 +15,7 @@ SC.MutableArrayTests.extend({
newObject: function(ary) {
var ret = ary ? ary.slice() : this.newFixture(3);
return SC.ArrayController.create({
- content: ret
+ content: SC.NativeArray.apply(ret)
});
},
| true |
Other | emberjs | ember.js | 1fa9fa630fc31a7310fd838c2ee51ac940464a9d.json | Fix EXTEND_PROTOTYPES for sproutcore-runtime | packages/sproutcore-runtime/tests/legacy_1x/mixins/observable/chained_test.js | @@ -30,7 +30,7 @@ test("chained observers on enumerable properties are triggered when the observed
var child4 = SC.Object.create({ name: "Nancy" });
set(family, 'momma', momma);
- set(momma, 'children', [child1, child2, child3]);
+ set(momma, 'children', SC.NativeArray.apply([child1, child2, child3]));
var observerFiredCount = 0;
SC.addObserver(family, 'momma.children.@each.name', this, function() { | true |
Other | emberjs | ember.js | 1fa9fa630fc31a7310fd838c2ee51ac940464a9d.json | Fix EXTEND_PROTOTYPES for sproutcore-runtime | packages/sproutcore-runtime/tests/legacy_1x/mixins/observable/observable_test.js | @@ -382,37 +382,37 @@ module("Computed properties", {
test("getting values should call function return value", function() {
// get each property twice. Verify return.
- var keys = 'computed computedCached dependent dependentCached'.w();
+ var keys = SC.String.w('computed computedCached dependent dependentCached');
keys.forEach(function(key) {
- equals(object.get(key), key, 'Try #1: object.get(%@) should run function'.fmt(key));
- equals(object.get(key), key, 'Try #2: object.get(%@) should run function'.fmt(key));
+ equals(object.get(key), key, SC.String.fmt('Try #1: object.get(%@) should run function', key));
+ equals(object.get(key), key, SC.String.fmt('Try #2: object.get(%@) should run function', key));
});
// verify each call count. cached should only be called once
- 'computedCalls dependentCalls'.w().forEach(function(key) {
- equals(object[key].length, 2, 'non-cached property %@ should be called 2x'.fmt(key));
+ SC.String.w('computedCalls dependentCalls').forEach(function(key) {
+ equals(object[key].length, 2, SC.String.fmt('non-cached property %@ should be called 2x', key));
});
- 'computedCachedCalls dependentCachedCalls'.w().forEach(function(key) {
- equals(object[key].length, 1, 'non-cached property %@ should be called 1x'.fmt(key));
+ SC.String.w('computedCachedCalls dependentCachedCalls').forEach(function(key) {
+ equals(object[key].length, 1, SC.String.fmt('non-cached property %@ should be called 1x', key));
});
});
test("setting values should call function return value", function() {
// get each property twice. Verify return.
- var keys = 'computed dependent computedCached dependentCached'.w();
- var values = 'value1 value2'.w();
+ var keys = SC.String.w('computed dependent computedCached dependentCached');
+ var values = SC.String.w('value1 value2');
keys.forEach(function(key) {
- equals(object.set(key, values[0]), object, 'Try #1: object.set(%@, %@) should run function'.fmt(key, values[0]));
+ equals(object.set(key, values[0]), object, SC.String.fmt('Try #1: object.set(%@, %@) should run function', key, values[0]));
- equals(object.set(key, values[1]), object, 'Try #2: object.set(%@, %@) should run function'.fmt(key, values[1]));
+ equals(object.set(key, values[1]), object, SC.String.fmt('Try #2: object.set(%@, %@) should run function', key, values[1]));
- equals(object.set(key, values[1]), object, 'Try #3: object.set(%@, %@) should not run function since it is setting same value as before'.fmt(key, values[1]));
+ equals(object.set(key, values[1]), object, SC.String.fmt('Try #3: object.set(%@, %@) should not run function since it is setting same value as before', key, values[1]));
});
@@ -425,9 +425,9 @@ test("setting values should call function return value", function() {
// Cached properties first check their cached value before setting the
// property. Other properties blindly call set.
expectedLength = 3;
- equals(calls.length, expectedLength, 'set(%@) should be called the right amount of times'.fmt(key));
+ equals(calls.length, expectedLength, SC.String.fmt('set(%@) should be called the right amount of times', key));
for(idx=0;idx<2;idx++) {
- equals(calls[idx], values[idx], 'call #%@ to set(%@) should have passed value %@'.fmt(idx+1, key, values[idx]));
+ equals(calls[idx], values[idx], SC.String.fmt('call #%@ to set(%@) should have passed value %@', idx+1, key, values[idx]));
}
});
@@ -634,7 +634,7 @@ module("Observable objects & object properties ", {
toggleVal: true,
observedProperty: 'beingWatched',
testRemove: 'observerToBeRemoved',
- normalArray: [1,2,3,4,5],
+ normalArray: SC.NativeArray.apply([1,2,3,4,5]),
getEach: function() {
var keys = ['normal','abnormal']; | true |
Other | emberjs | ember.js | 1fa9fa630fc31a7310fd838c2ee51ac940464a9d.json | Fix EXTEND_PROTOTYPES for sproutcore-runtime | packages/sproutcore-runtime/tests/legacy_1x/mixins/observable/observersForKey_test.js | @@ -36,14 +36,14 @@ test("should get observers", function() {
o3 = ObservableObject.create({ func: function() {} }),
observers = null;
- equals(o1.observersForKey('foo').get('length'), 0, "o1.observersForKey should return empty array");
+ equals(SC.get(o1.observersForKey('foo'), 'length'), 0, "o1.observersForKey should return empty array");
o1.addObserver('foo', o2, o2.func);
o1.addObserver('foo', o3, o3.func);
observers = o1.observersForKey('foo');
- equals(observers.get('length'), 2, "o2.observersForKey should return an array with length 2");
+ equals(SC.get(observers, 'length'), 2, "o2.observersForKey should return an array with length 2");
equals(observers[0][0], o2, "first item in observers array should be o2");
equals(observers[1][0], o3, "second item in observers array should be o3");
}); | true |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.