Created
June 4, 2017 11:28
-
-
Save nirazul/e44f0e6f0eb9f3361cb4088f924b8647 to your computer and use it in GitHub Desktop.
Map global filters to local methods to use them in components as well as templates
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
/** | |
* Map global filters for being used from within `methods`. This makes them usable in js as well as templates | |
* @param {Array} filters - A list of registered filter names | |
* @return {Object) An object containing filters and their functions | |
*/ | |
export function mapFilters(filters) { | |
return filters.reduce((result, filter) => { | |
result[filter] = function(...args) { | |
return this.$options.filters[filter](...args); | |
}; | |
return result; | |
}, {}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment