Skip to content

Instantly share code, notes, and snippets.

@nirazul
Created June 4, 2017 11:28
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save nirazul/e44f0e6f0eb9f3361cb4088f924b8647 to your computer and use it in GitHub Desktop.
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
/**
* 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