Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUGFIX release] Deprecate Function#observesBefore #11798

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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