Skip to content

Commit

Permalink
Merge pull request #15894 from bekzod/remove-immediate-observer
Browse files Browse the repository at this point in the history
[CLEANUP] removed `immediateObserver`
  • Loading branch information
rwjblue authored Dec 1, 2017
2 parents 3844b42 + eac72db commit 1723b73
Show file tree
Hide file tree
Showing 6 changed files with 0 additions and 188 deletions.
1 change: 0 additions & 1 deletion packages/ember-metal/lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,6 @@ export {
export {
Mixin,
aliasMethod,
_immediateObserver,
_beforeObserver,
mixin,
observer,
Expand Down
41 changes: 0 additions & 41 deletions packages/ember-metal/lib/mixin.js
Original file line number Diff line number Diff line change
Expand Up @@ -774,47 +774,6 @@ export function observer(...args) {
return func;
}

/**
Specify a method that observes property changes.
```javascript
import EmberObject from '@ember/object';
EmberObject.extend({
valueObserver: Ember.immediateObserver('value', function() {
// Executes whenever the "value" property changes
})
});
```
In the future, `observer` may become asynchronous. In this event,
`immediateObserver` will maintain the synchronous behavior.
Also available as `Function.prototype.observesImmediately` if prototype extensions are
enabled.
@method _immediateObserver
@for Ember
@param {String} propertyNames*
@param {Function} func
@deprecated Use `observer` instead.
@return func
@private
*/
export function _immediateObserver() {
deprecate('Usage of `Ember.immediateObserver` is deprecated, use `observer` instead.', false, { id: 'ember-metal.immediate-observer', until: '3.0.0' });

for (let i = 0; i < arguments.length; i++) {
let arg = arguments[i];
assert(
'Immediate observers must observe internal properties only, not properties on other objects.',
typeof arg !== 'string' || arg.indexOf('.') === -1
);
}

return observer.apply(this, arguments);
}

/**
When observers fire, they are called with the arguments `obj`, `keyName`.
Expand Down
110 changes: 0 additions & 110 deletions packages/ember-metal/tests/observer_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import {
mixin,
observer,
_beforeObserver,
_immediateObserver,
run,
beginPropertyChanges,
endPropertyChanges,
Expand Down Expand Up @@ -965,115 +964,6 @@ testBoth('setting a cached computed property whose value has changed should trig
equal(get(obj, 'foo'), 'bar');
});

QUnit.module('Ember.immediateObserver (Deprecated)');

testBoth('immediate observers should fire synchronously', function(get, set) {
expectDeprecation(/Usage of `Ember.immediateObserver` is deprecated, use `observer` instead./);
let obj = {};
let observerCalled = 0;
let mixin;

// explicitly create a run loop so we do not inadvertently
// trigger deferred behavior
run(function() {
mixin = Mixin.create({
fooDidChange: _immediateObserver('foo', function() {
observerCalled++;
equal(get(this, 'foo'), 'barbaz', 'newly set value is immediately available');
})
});

mixin.apply(obj);

defineProperty(obj, 'foo', computed({
get: function() { return 'yes hello this is foo'; },
set: function(key, value) { return value; }
}));

equal(get(obj, 'foo'), 'yes hello this is foo', 'precond - computed property returns a value');
equal(observerCalled, 0, 'observer has not yet been called');

set(obj, 'foo', 'barbaz');

equal(observerCalled, 1, 'observer was called once');
});
});


if (ENV.EXTEND_PROTOTYPES.Function) {
testBoth('immediate observers added declaratively via brace expansion fire synchronously', function (get, set) {
let obj = {};
let observerCalled = 0;
let mixin;

// explicitly create a run loop so we do not inadvertently
// trigger deferred behavior
run(function() {
expectDeprecation(function() {
mixin = Mixin.create({
fooDidChange: function() {
observerCalled++;
equal(get(this, 'foo'), 'barbaz', 'newly set value is immediately available');
}.observesImmediately('{foo,bar}')
});
}, /Function#observesImmediately is deprecated. Use Function#observes instead/);

mixin.apply(obj);

defineProperty(obj, 'foo', computed({
get: function(key) { return 'yes hello this is foo'; },
set: function(key, value) { return value; }
}));

equal(get(obj, 'foo'), 'yes hello this is foo', 'precond - computed property returns a value');
equal(observerCalled, 0, 'observer has not yet been called');

set(obj, 'foo', 'barbaz');

equal(observerCalled, 1, 'observer was called once');
});
});
}

testBoth('immediate observers watching multiple properties via brace expansion fire synchronously', function (get, set) {
expectDeprecation(/Usage of `Ember.immediateObserver` is deprecated, use `observer` instead./);
let obj = {};
let observerCalled = 0;
let mixin;

// explicitly create a run loop so we do not inadvertently
// trigger deferred behavior
run(function() {
mixin = Mixin.create({
fooDidChange: _immediateObserver('{foo,bar}', function() {
observerCalled++;
equal(get(this, 'foo'), 'barbaz', 'newly set value is immediately available');
})
});

mixin.apply(obj);

defineProperty(obj, 'foo', computed({
get: function() { return 'yes hello this is foo'; },
set: function(key, value) { return value; }
}));

equal(get(obj, 'foo'), 'yes hello this is foo', 'precond - computed property returns a value');
equal(observerCalled, 0, 'observer has not yet been called');

set(obj, 'foo', 'barbaz');

equal(observerCalled, 1, 'observer was called once');
});
});

testBoth('immediate observers are for internal properties only', function(get, set) {
expectDeprecation(/Usage of `Ember.immediateObserver` is deprecated, use `observer` instead./);
expectAssertion(function() {
_immediateObserver('foo.bar', function() { return this; });
}, 'Immediate observers must observe internal properties only, not properties on other objects.');
});

QUnit.module('changeProperties');

testBoth('observers added/removed during changeProperties should do the right thing.', function(get, set) {
Expand Down
34 changes: 0 additions & 34 deletions packages/ember-runtime/lib/ext/function.js
Original file line number Diff line number Diff line change
Expand Up @@ -131,40 +131,6 @@ if (ENV.EXTEND_PROTOTYPES.Function) {
// observes handles property expansion
return this.observes(...arguments);
};
/**
The `observesImmediately` extension of Javascript's Function prototype is
available when `EmberENV.EXTEND_PROTOTYPES` or
`EmberENV.EXTEND_PROTOTYPES.Function` is true, which is the default.
You can observe property changes simply by adding the `observesImmediately`
call to the end of your method declarations in classes that you write.
For example:
```javascript
import EmberObject from '@ember/object';
EmberObject.extend({
valueObserver: function() {
// Executes immediately after the "value" property changes
}.observesImmediately('value')
});
```
In the future, `observes` may become asynchronous. In this event,
`observesImmediately` will maintain the synchronous behavior.
See `Ember.immediateObserver`.
@method observesImmediately
@for Function
@deprecated
@private
*/
FunctionPrototype.observesImmediately = deprecateFunc(
'Function#observesImmediately is deprecated. Use Function#observes instead',
{ id: 'ember-runtime.ext-function', until: '3.0.0' },
FunctionPrototype._observesImmediately
);

/**
The `on` extension of Javascript's Function prototype is available
Expand Down
1 change: 0 additions & 1 deletion packages/ember/lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,6 @@ Ember._suspendObservers = metal._suspendObservers;
Ember.required = metal.required;
Ember.aliasMethod = metal.aliasMethod;
Ember.observer = metal.observer;
Ember.immediateObserver = metal._immediateObserver;
Ember.mixin = metal.mixin;
Ember.Mixin = metal.Mixin;
Ember.bind = metal.bind;
Expand Down
1 change: 0 additions & 1 deletion packages/ember/tests/reexports_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,6 @@ QUnit.module('ember reexports');
['required', 'ember-metal'],
['aliasMethod', 'ember-metal'],
['observer', 'ember-metal'],
['immediateObserver', 'ember-metal', '_immediateObserver'],
['mixin', 'ember-metal'],
['Mixin', 'ember-metal'],
['bind', 'ember-metal'],
Expand Down

0 comments on commit 1723b73

Please sign in to comment.