Permalink
Browse files

Remove CP_DEFAULT_CACHEABLE flag

Computed Properties will always be cached by default. Use `volatile` to
change this on a per-property basis.
  • Loading branch information...
wagenet committed Oct 20, 2012
1 parent 710d1e1 commit 5ef55f22c584abc788fd98994af591f010ba82e9
Showing with 90 additions and 111 deletions.
  1. +0 −1 Rakefile
  2. +3 −3 packages/ember-handlebars/lib/controls/button.js
  3. +3 −3 packages/ember-handlebars/lib/controls/select.js
  4. +1 −1 packages/ember-handlebars/tests/controls/select_test.js
  5. +1 −1 packages/ember-handlebars/tests/handlebars_test.js
  6. +1 −1 packages/ember-handlebars/tests/helpers/yield_test.js
  7. +1 −1 packages/ember-handlebars/tests/views/collection_view_test.js
  8. +6 −6 packages/ember-metal/lib/computed.js
  9. +0 −14 packages/ember-metal/lib/core.js
  10. +1 −1 packages/ember-metal/lib/properties.js
  11. +13 −13 packages/ember-metal/tests/computed_test.js
  12. +2 −2 packages/ember-metal/tests/observer_test.js
  13. +7 −7 packages/ember-routing/lib/routable.js
  14. +5 −5 packages/ember-runtime/lib/mixins/array.js
  15. +1 −1 packages/ember-runtime/lib/mixins/deferred.js
  16. +4 −4 packages/ember-runtime/lib/mixins/enumerable.js
  17. +1 −1 packages/ember-runtime/lib/mixins/sortable.js
  18. +1 −1 packages/ember-runtime/lib/mixins/target_action_support.js
  19. +2 −2 packages/ember-runtime/lib/system/array_proxy.js
  20. +1 −1 packages/ember-runtime/lib/system/each_proxy.js
  21. +2 −2 packages/ember-runtime/lib/system/set.js
  22. +6 −6 packages/ember-runtime/tests/legacy_1x/mixins/observable/observable_test.js
  23. +2 −2 packages/ember-runtime/tests/mixins/array_test.js
  24. +1 −1 packages/ember-runtime/tests/mixins/enumerable_test.js
  25. +1 −1 packages/ember-runtime/tests/mixins/mutable_array_test.js
  26. +1 −1 packages/ember-runtime/tests/mixins/mutable_enumerable_test.js
  27. +1 −1 packages/ember-runtime/tests/mixins/observable_test.js
  28. +1 −1 packages/ember-runtime/tests/suites/enumerable.js
  29. +7 −7 packages/ember-runtime/tests/system/object/computed_test.js
  30. +2 −2 packages/ember-states/lib/state.js
  31. +1 −1 packages/ember-states/lib/state_manager.js
  32. +1 −1 packages/ember-views/lib/views/container_view.js
  33. +10 −10 packages/ember-views/lib/views/view.js
  34. +0 −6 tests/index.html
View
@@ -80,7 +80,6 @@ task :test, [:suite] => :dist do |t, args|
"package=all&jquery=git&nojshint=true",
"package=all&extendprototypes=true&nojshint=true",
"package=all&extendprototypes=true&jquery=git&nojshint=true",
"package=all&nocpdefaultcacheable=true&nojshint=true",
"package=all&dist=build&nojshint=true"]
}
@@ -40,22 +40,22 @@ Ember.Button = Ember.View.extend(Ember.TargetActionSupport, {
if (typeof target !== 'string') { return target; }
return Ember.Handlebars.getPath(root, target, { data: data });
}).property('target').cacheable(),
}).property('target'),
// Defaults to 'button' if tagName is 'input' or 'button'
type: Ember.computed(function(key, value) {
var tagName = this.get('tagName');
if (value !== undefined) { this._type = value; }
if (this._type !== undefined) { return this._type; }
if (tagName === 'input' || tagName === 'button') { return 'button'; }
}).property('tagName').cacheable(),
}).property('tagName'),
disabled: false,
// Allow 'a' tags to act like buttons
href: Ember.computed(function() {
return this.get('tagName') === 'a' ? '#' : null;
}).property('tagName').cacheable(),
}).property('tagName'),
mouseDown: function() {
if (!get(this, 'disabled')) {
@@ -325,7 +325,7 @@ Ember.Select = Ember.View.extend(
var valuePath = get(this, 'optionValuePath').replace(/^content\.?/, '');
return valuePath ? get(this, 'selection.' + valuePath) : get(this, 'selection');
}).property('selection').cacheable(),
}).property('selection'),
/**
If given, a top-most dummy option will be rendered to serve as a user
@@ -510,7 +510,7 @@ Ember.SelectOption = Ember.View.extend({
Ember.defineProperty(this, 'label', Ember.computed(function() {
return get(this, labelPath);
}).property(labelPath).cacheable());
}).property(labelPath));
}, 'parentView.optionLabelPath'),
valuePathDidChange: Ember.observer(function() {
@@ -520,6 +520,6 @@ Ember.SelectOption = Ember.View.extend({
Ember.defineProperty(this, 'value', Ember.computed(function() {
return get(this, valuePath);
}).property(valuePath).cacheable());
}).property(valuePath));
}, 'parentView.optionValuePath')
});
@@ -461,7 +461,7 @@ test("works from a template with bindings", function() {
fullName: Ember.computed(function() {
return this.get('firstName') + " " + this.get('lastName');
}).property('firstName', 'lastName').cacheable()
}).property('firstName', 'lastName')
});
var erik = Person.create({id: 4, firstName: 'Erik', lastName: 'Bryn'});
@@ -112,7 +112,7 @@ test("template view should call the function of the associated template with its
personName: Ember.computed(function() {
this._i++;
return this._personName + this._i;
}).cacheable(),
}),
templates: Ember.Object.create({
test_template: Ember.Handlebars.compile("<h1 id='twas-called'>template was called for {{personName}}. Yea {{personName}}</h1>")
@@ -69,7 +69,7 @@ test("templates should yield to block, when the yield is embedded in a hierarchy
indexArray[i] = i;
}
return indexArray;
}).property().cacheable()
}).property()
});
view = Ember.View.create({
@@ -446,7 +446,7 @@ test("should render multiple, bound nested collections (#68)", function() {
template: Ember.Handlebars.compile('{{#collection TemplateTests.InnerList class="inner"}}{{content}}{{/collection}}{{content}}'),
innerListContent: Ember.computed(function() {
return Ember.A([1,2,3]);
}).cacheable()
})
});
TemplateTests.OuterList = Ember.CollectionView.extend({
@@ -8,7 +8,7 @@ require('ember-metal/watching');
@module ember-metal
*/
Ember.warn("Computed properties will soon be cacheable by default. To enable this in your app, set `ENV.CP_DEFAULT_CACHEABLE = true`.", Ember.CP_DEFAULT_CACHEABLE);
Ember.warn("The CP_DEFAULT_CACHEABLE flag has been removed and computed properties are always cached by default. Use `volatile` if you don't want caching.", Ember.ENV.CP_DEFAULT_CACHEABLE !== false);
var get = Ember.get,
@@ -119,7 +119,7 @@ function removeDependentKeys(desc, obj, keyName, meta) {
*/
function ComputedProperty(func, opts) {
this.func = func;
this._cacheable = (opts && opts.cacheable !== undefined) ? opts.cacheable : Ember.CP_DEFAULT_CACHEABLE;
this._cacheable = (opts && opts.cacheable !== undefined) ? opts.cacheable : true;
this._dependentKeys = opts && opts.dependentKeys;
}
@@ -140,7 +140,7 @@ var ComputedPropertyPrototype = ComputedProperty.prototype;
// After calculating the value of this function, Ember.js will
// return that value without re-executing this function until
// one of the dependent properties change.
}.property('firstName', 'lastName').cacheable()
}.property('firstName', 'lastName')
});
Properties are cacheable by default.
@@ -401,7 +401,7 @@ Ember.cacheFor = function cacheFor(obj, key) {
Ember.computed.not = function(dependentKey) {
return Ember.computed(dependentKey, function(key) {
return !get(this, dependentKey);
}).cacheable();
});
};
/**
@@ -413,7 +413,7 @@ Ember.computed.empty = function(dependentKey) {
return Ember.computed(dependentKey, function(key) {
var val = get(this, dependentKey);
return val === undefined || val === null || val === '' || (Ember.isArray(val) && get(val, 'length') === 0);
}).cacheable();
});
};
/**
@@ -424,5 +424,5 @@ Ember.computed.empty = function(dependentKey) {
Ember.computed.bool = function(dependentKey) {
return Ember.computed(dependentKey, function(key) {
return !!get(this, dependentKey);
}).cacheable();
});
};
@@ -109,20 +109,6 @@ Ember.LOG_STACKTRACE_ON_DEPRECATION = (Ember.ENV.LOG_STACKTRACE_ON_DEPRECATION !
*/
Ember.SHIM_ES5 = (Ember.ENV.SHIM_ES5 === false) ? false : Ember.EXTEND_PROTOTYPES;
/**
Determines whether computed properties are cacheable by default.
This option will be removed for the 1.1 release.
When caching is enabled by default, you can use `volatile()` to disable
caching on individual computed properties.
@property CP_DEFAULT_CACHEABLE
@type Boolean
@default true
*/
Ember.CP_DEFAULT_CACHEABLE = (Ember.ENV.CP_DEFAULT_CACHEABLE !== false);
/**
Empty function. Useful for some operations.
@@ -69,7 +69,7 @@ var Descriptor = Ember.Descriptor = function() {};
// define a computed property
Ember.defineProperty(contact, 'fullName', Ember.computed(function() {
return this.firstName+' '+this.lastName;
}).property('firstName', 'lastName').cacheable());
}).property('firstName', 'lastName'));
@method defineProperty
@for Ember
@@ -181,7 +181,7 @@ module('Ember.computed - cacheable', {
Ember.defineProperty(obj, 'foo', Ember.computed(function() {
count++;
return 'bar '+count;
}).cacheable());
}));
},
teardown: function() {
@@ -230,7 +230,7 @@ testBoth('cacheFor should return falsy cached values', function(get, set) {
Ember.defineProperty(obj, 'falsy', Ember.computed(function() {
return false;
}).cacheable());
}));
equal(Ember.cacheFor(obj, 'falsy'), undefined, "should not yet be a cached value");
@@ -250,7 +250,7 @@ module('Ember.computed - dependentkey', {
Ember.defineProperty(obj, 'foo', Ember.computed(function() {
count++;
return 'bar '+count;
}).property('bar').cacheable());
}).property('bar'));
},
teardown: function() {
@@ -293,7 +293,7 @@ testBoth('should invalidate multiple nested dependent keys', function(get, set)
Ember.defineProperty(obj, 'bar', Ember.computed(function() {
count++;
return 'baz '+count;
}).property('baz').cacheable());
}).property('baz'));
equal(Ember.isWatching(obj, 'bar'), false, 'precond not watching dependent key');
equal(Ember.isWatching(obj, 'baz'), false, 'precond not watching dependent key');
@@ -317,12 +317,12 @@ testBoth('circular keys should not blow up', function(get, set) {
Ember.defineProperty(obj, 'bar', Ember.computed(function() {
count++;
return 'bar '+count;
}).property('foo').cacheable());
}).property('foo'));
Ember.defineProperty(obj, 'foo', Ember.computed(function() {
count++;
return 'foo '+count;
}).property('bar').cacheable());
}).property('bar'));
equal(get(obj, 'foo'), 'foo 1', 'get once');
equal(get(obj, 'foo'), 'foo 1', 'cached retrieve');
@@ -342,7 +342,7 @@ testBoth('redefining a property should undo old depenent keys', function(get ,se
Ember.defineProperty(obj, 'foo', Ember.computed(function() {
count++;
return 'baz '+count;
}).property('baz').cacheable());
}).property('baz'));
equal(Ember.isWatching(obj, 'bar'), false, 'after redefining should not be watching dependent key');
@@ -399,7 +399,7 @@ testBoth('depending on simple chain', function(get, set) {
// assign computed property
Ember.defineProperty(obj, 'prop',
Ember.computed(func).property('foo.bar.baz.biff').cacheable());
Ember.computed(func).property('foo.bar.baz.biff'));
equal(get(obj, 'prop'), 'BIFF 1');
@@ -447,7 +447,7 @@ testBoth('depending on Global chain', function(get, set) {
Ember.defineProperty(obj, 'prop', Ember.computed(function() {
count++;
return Ember.get('Global.foo.bar.baz.biff')+' '+count;
}).property('Global.foo.bar.baz.biff').cacheable());
}).property('Global.foo.bar.baz.biff'));
equal(get(obj, 'prop'), 'BIFF 1');
@@ -490,8 +490,8 @@ testBoth('depending on Global chain', function(get, set) {
});
testBoth('chained dependent keys should evaluate computed properties lazily', function(get,set){
Ember.defineProperty(obj.foo.bar, 'b', Ember.computed(func).property().cacheable());
Ember.defineProperty(obj.foo, 'c', Ember.computed(function(){}).property('bar.b').cacheable());
Ember.defineProperty(obj.foo.bar, 'b', Ember.computed(func).property());
Ember.defineProperty(obj.foo, 'c', Ember.computed(function(){}).property('bar.b'));
equal(count, 0, 'b should not run');
});
@@ -530,7 +530,7 @@ testBoth('setting a watched computed property', function(get, set) {
return value;
}
return get(this, 'firstName') + ' ' + get(this, 'lastName');
}).property('firstName', 'lastName').cacheable()
}).property('firstName', 'lastName')
);
var fullNameWillChange = 0,
fullNameDidChange = 0,
@@ -586,7 +586,7 @@ testBoth('setting a cached computed property that modifies the value you give it
return value + 1;
}
return get(this, 'foo') + 1;
}).property('foo').cacheable()
}).property('foo')
);
var plusOneWillChange = 0,
plusOneDidChange = 0;
@@ -683,7 +683,7 @@ testBoth('setting a cached computed property whose value has changed should trig
Ember.defineProperty(obj, 'foo', Ember.computed(function(key, value) {
if (arguments.length === 2) { return value; }
return get(this, 'baz');
}).property('baz').cacheable());
}).property('baz'));
var count = 0;
@@ -727,7 +727,7 @@ testBoth("immediate observers should fire synchronously", function(get, set) {
return value;
}
return "yes hello this is foo";
}).cacheable());
}));
equal(get(obj, 'foo'), "yes hello this is foo", "precond - computed property returns a value");
equal(observerCalled, 0, "observer has not yet been called");
@@ -161,7 +161,7 @@ Ember.Routable = Ember.Mixin.create({
*/
isRoutable: Ember.computed(function() {
return typeof get(this, 'route') === 'string';
}).cacheable(),
}),
/**
@private
@@ -174,7 +174,7 @@ Ember.Routable = Ember.Mixin.create({
isLeafRoute: Ember.computed(function() {
if (get(this, 'isLeaf')) { return true; }
return !get(this, 'childStates').findProperty('isRoutable');
}).cacheable(),
}),
/**
@private
@@ -190,7 +190,7 @@ Ember.Routable = Ember.Mixin.create({
if (route) {
return Ember._RouteMatcher.create({ route: route });
}
}).cacheable(),
}),
/**
@private
@@ -206,7 +206,7 @@ Ember.Routable = Ember.Mixin.create({
if (routeMatcher) {
return routeMatcher.identifiers.length > 0;
}
}).cacheable(),
}),
/**
@private
@@ -226,7 +226,7 @@ Ember.Routable = Ember.Mixin.create({
} else {
return modelType;
}
}).cacheable(),
}),
/**
@private
@@ -474,7 +474,7 @@ Ember.Routable = Ember.Mixin.create({
}
return 'application';
}).cacheable(),
}),
_template: Ember.computed(function(key, value) {
if (arguments.length > 1) { return value; }
@@ -492,7 +492,7 @@ Ember.Routable = Ember.Mixin.create({
baseName = baseName.replace(/Route$/, '');
return baseName.charAt(0).toLowerCase() + baseName.substr(1);
}
}).cacheable(),
}),
render: function(options) {
options = options || {};
Oops, something went wrong.

0 comments on commit 5ef55f2

Please sign in to comment.