Skip to content

Commit

Permalink
revert 93a911b
Browse files Browse the repository at this point in the history
Ember.run.proxy will return as Ember.run.bind
  • Loading branch information
stefanpenner committed Jan 3, 2014
1 parent 2f979e2 commit 9509b4b
Show file tree
Hide file tree
Showing 5 changed files with 5 additions and 174 deletions.
14 changes: 0 additions & 14 deletions FEATURES.md
Original file line number Diff line number Diff line change
Expand Up @@ -122,20 +122,6 @@ for a detailed explanation.

Added in [#3879](https://github.com/emberjs/ember.js/pull/3879)

* `ember-metal-run-proxy`

Enables `Ember.run.proxy` which is ember run-loop aware variation of
jQuery.proxy. Useful for integrating with 3rd party callbacks.

Added in [#3991](https://github.com/emberjs/ember.js/pull/3991).

* `ember-metal-run-method`

Enables `Ember.run.method` which constructs a function guarenteed to
be wrapped in a function. Useful for integrating with 3rd party callbacks.

Added in [#3991](https://github.com/emberjs/ember.js/pull/3991).

* `query-params-new`

Add query params support to the ember router. This is a rewrite of a
Expand Down
4 changes: 1 addition & 3 deletions features.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,7 @@
"ember-testing-routing-helpers": null,
"ember-testing-triggerEvent-helper": null,
"with-controller": null,
"computed-read-only": null,
"ember-metal-run-proxy": null,
"ember-metal-run-method": null
"computed-read-only": null
},
"debugStatements": ["Ember.warn", "Ember.assert", "Ember.deprecate", "Ember.debug", "Ember.Logger.info"]
}
124 changes: 4 additions & 120 deletions packages/ember-metal/lib/run_loop.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@ var Backburner = requireModule('backburner').Backburner,
onBegin: onBegin,
onEnd: onEnd
}),
slice = [].slice,
concat = [].concat;
slice = [].slice;

// ..........................................................
// Ember.run - this is ideally the only public API the dev sees
Expand Down Expand Up @@ -105,7 +104,7 @@ Ember.run = function(target, method) {
@return {Object} Return value from invoking the passed function. Please note,
when called within an existing loop, no return value is possible.
*/
Ember.run.join = function(target, method /* args */) {
Ember.run.join = function(target, method) {
if (!Ember.run.currentRunLoop) {
return Ember.run.apply(Ember.run, arguments);
}
Expand All @@ -115,121 +114,6 @@ Ember.run.join = function(target, method /* args */) {
Ember.run.schedule.apply(Ember.run, args);
};

if (Ember.FEATURES.isEnabled('ember-metal-run-proxy')) {
/**
Provides a useful utility for when integrating with non-Ember libraries
that provide asynchronous callbacks.
Ember utilizes a run-loop to batch and coalesce changes. This works by
marking the start and end of Ember-related Javascript execution.
When using events such as a View's click handler, Ember wraps the event
handler in a run-loop, but when integrating with non-Ember libraries this
can be tedious.
For example, the following is rather verbose but is the correct way to combine
third-party events and Ember code.
```javascript
var that = this;
jQuery(window).on('resize', function(){
Ember.run(function(){
that.handleResize();
});
});
```
To reduce the boilerplate, the following can be used to construct a
run-loop-wrapped callback handler.
```javascript
jQuery(window).on('resize', Ember.run.proxy(this, this.triggerResize));
```
@method proxy
@namespace Ember.run
@param {Object} [target] target of method to call
@param {Function|String} method Method to invoke.
May be a function or a string. If you pass a string
then it will be looked up on the passed target.
@param {Object} [args*] Any additional arguments you wish to pass to the method.
@return {Object} return value from invoking the passed function. Please note,
when called within an existing loop, no return value is possible.
*/
Ember.run.proxy = function(target, method /* args*/) {
var args = arguments;
return function() {
return Ember.run.join.apply(Ember.run, args);
};
};
}

if (Ember.FEATURES.isEnabled('ember-metal-run-method')) {
/**
Provides a useful utility for use when integrating with non-Ember libraries
that provide asynchronous callbacks.
Ember utilizes a run-loop to batch and coalesce changes. This works by
marking the start and end of Ember-related Javascript execution.
When using events such as a View's click handler, Ember wraps the event
handler in a run-loop, but when integrating with non-Ember libraries this
can be tedious.
For example, the following is rather verbose but the correct way to combine
third-party events and Ember code.
```javascript
var object = Ember.Object.create({
handleResize: function(dimensions){
this.set('somethingThatNeedsTheRunLoop', dimensions);
};
});
jQuery(window).on('resize', function(){
var dimensions = extractDimensions();
Ember.run(function(){
object.handleResize(dimensions);
));
});
```
To reduce the boilerplate, the following can be used to construct a
run-loop-wrapped callback handler.
```javascript
var object = Ember.Object.create({
handleResize: Ember.run.method(function(dimensions){
this.set('somethingThatNeedsTheRunLoop', dimensions);
})
});
jQuery(window).on('scroll', function(){
var dimensions = interpolateDimensions();
object.handleResize(dimensions);
});
jQuery(window).on('resize', function(){
var dimensions = extractDimensions();
object.handleResize(dimensions);
});
```
@method method
@namespace Ember.run
@param {Function} method a method to wrap
@return {Object} A method guarenteed to be run-loop-wrapped.
*/
Ember.run.method = function() {
var args = slice.call(arguments);

return function() {
args.unshift(this); // ensure the context is the class the method was defined on.
return Ember.run.join.apply(Ember.run, concat.call(args, slice.call(arguments)));
};
};
}

Ember.run.backburner = backburner;

var run = Ember.run;
Expand Down Expand Up @@ -523,7 +407,7 @@ Ember.run.next = function() {

/**
Cancels a scheduled item. Must be a value returned by `Ember.run.later()`,
`Ember.run.once()`, `Ember.run.next()`, `Ember.run.debounce()`, or
`Ember.run.once()`, `Ember.run.next()`, `Ember.run.debounce()`, or
`Ember.run.throttle()`.
```javascript
Expand Down Expand Up @@ -612,7 +496,7 @@ Ember.run.cancel = function(timer) {
Ember.run.debounce(myContext, myFunc, 150, true);
// 150ms passes and nothing else is logged to the console and
// 150ms passes and nothing else is logged to the console and
// the debouncee is no longer being watched
Ember.run.debounce(myContext, myFunc, 150, true);
Expand Down
18 changes: 0 additions & 18 deletions packages/ember-metal/tests/run_loop/run_method_test.js

This file was deleted.

19 changes: 0 additions & 19 deletions packages/ember-metal/tests/run_loop/run_proxy_test.js

This file was deleted.

0 comments on commit 9509b4b

Please sign in to comment.