-
Notifications
You must be signed in to change notification settings - Fork 275
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: modify fa-pipe-from and fa-pipe-to to unbind their event listene…
…rs when their scopes are destroyed Wraps common logic for fa-pipe-from and fa-pipe-to in a service
- Loading branch information
Showing
3 changed files
with
86 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
/** | ||
* @ngdoc service | ||
* @name $famousPipe | ||
* @module famous.angular | ||
* @description | ||
* Provides common helpers for the event pipe directives fa-pipe-from and fa-pipe-to. | ||
*/ | ||
|
||
angular.module('famous.angular') | ||
.service('$famousPipe', function() { | ||
|
||
/** | ||
* @param {EventHandler|Array} pipes - pipes to negotatiate | ||
* @param {Engine|RenderNode|Array} targets - nodes to negotiate | ||
* @param {String} method - action to apply from targets to pipes, e.g. "pipe" or "unpipe" | ||
*/ | ||
function bulkUpdatePipes(pipes, targets, method) { | ||
if (! (pipes instanceof Array)) { | ||
pipes = [pipes]; | ||
} | ||
|
||
if (! (targets instanceof Array)) { | ||
targets = [targets]; | ||
} | ||
|
||
for (var i = 0; i < pipes.length; i++) { | ||
for (var j = 0; j < targets.length; j++) { | ||
if (targets[j] !== undefined && pipes[i] !== undefined) { | ||
targets[j][method](pipes[i]); | ||
} | ||
} | ||
} | ||
} | ||
|
||
/** | ||
* @ngdoc method | ||
* @name $famousPipe#unpipesFromTargets | ||
* @module famous.angular | ||
* @param {EventHandler|Array} pipes - pipes to unpipe | ||
* @param {Engine|RenderNode|Array} targets - nodes to unpipe from | ||
* @description | ||
* Unpipes the specified pipes from the specified targets. | ||
*/ | ||
this.unpipesFromTargets = function(pipes, targets) { | ||
bulkUpdatePipes(pipes, targets, "unpipe"); | ||
}; | ||
|
||
/** | ||
* @ngdoc method | ||
* @name $famousPipe#pipesToTargets | ||
* @module famous.angular | ||
* @param {EventHandler|Array} pipes - pipes to pipe | ||
* @param {Engine|RenderNode|Array} targets - nodes to pipe to | ||
* @description | ||
* Pipes the specified pipes to the specified targets. | ||
*/ | ||
this.pipesToTargets = function(pipes, targets) { | ||
bulkUpdatePipes(pipes, targets, "pipe"); | ||
}; | ||
}); |