Skip to content

Commit

Permalink
Merge pull request #11798 from cibernox/deprecate_function_prototype_…
Browse files Browse the repository at this point in the history
…observesBefore

[BUGFIX release] Deprecate Function#observesBefore
  • Loading branch information
rwjblue committed Jul 17, 2015
2 parents 693a8e9 + 4e965be commit 3ad211d
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 14 deletions.
2 changes: 2 additions & 0 deletions packages/ember-metal/tests/observer_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -707,6 +707,7 @@ testBoth('observer should fire before dependent property is modified', function(

if (Ember.EXTEND_PROTOTYPES) {
testBoth('before observer added declaratively via brace expansion should fire when property changes', function (get, set) {
expectDeprecation(/Function#observesBefore is deprecated and will be removed in the near future/);
var obj = {};
var count = 0;

Expand All @@ -727,6 +728,7 @@ if (Ember.EXTEND_PROTOTYPES) {
});

testBoth('before observer specified declaratively via brace expansion should fire when dependent property changes', function (get, set) {
expectDeprecation(/Function#observesBefore is deprecated and will be removed in the near future/);
var obj = { baz: 'Initial' };
var count = 0;

Expand Down
30 changes: 16 additions & 14 deletions packages/ember-runtime/lib/ext/function.js
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,21 @@ if (Ember.EXTEND_PROTOTYPES === true || Ember.EXTEND_PROTOTYPES.Function) {
*/
FunctionPrototype.observesImmediately = Ember.deprecateFunc('Function#observesImmediately is deprecated. Use Function#observes instead', FunctionPrototype._observesImmediately);


FunctionPrototype._observesBefore = function () {
var watched = [];
var addWatchedProperty = function (obs) {
watched.push(obs);
};

for (var i = 0, l = arguments.length; i < l; ++i) {
expandProperties(arguments[i], addWatchedProperty);
}

this.__ember_observesBefore__ = watched;

return this;
};
/**
The `observesBefore` extension of Javascript's Function prototype is
available when `Ember.EXTEND_PROTOTYPES` or
Expand All @@ -175,20 +190,7 @@ if (Ember.EXTEND_PROTOTYPES === true || Ember.EXTEND_PROTOTYPES.Function) {
@for Function
@private
*/
FunctionPrototype.observesBefore = function () {
var watched = [];
var addWatchedProperty = function (obs) {
watched.push(obs);
};

for (var i = 0, l = arguments.length; i < l; ++i) {
expandProperties(arguments[i], addWatchedProperty);
}

this.__ember_observesBefore__ = watched;

return this;
};
FunctionPrototype.observesBefore = Ember.deprecateFunc('Function#observesBefore is deprecated and will be removed in the near future.', { url: 'http://emberjs.com/deprecations/v1.x/#toc_beforeobserver' }, FunctionPrototype._observesBefore);

/**
The `on` extension of Javascript's Function prototype is available
Expand Down

0 comments on commit 3ad211d

Please sign in to comment.