Sha256: b13bb7302c83cd74beef0c611b9fba7981784ae6abf54bfcd8e1f8e3d8847812
Contents?: true
Size: 1.61 KB
Versions: 5
Compression:
Stored size: 1.61 KB
Contents
var _ = require('./debug') /** * Resolve read & write filters for a vm instance. The * filters descriptor Array comes from the directive parser. * * This is extracted into its own utility so it can * be used in multiple scenarios. * * @param {Vue} vm * @param {Array<Object>} filters * @param {Object} [target] * @return {Object} */ exports.resolveFilters = function (vm, filters, target) { if (!filters) { return } var res = target || {} // var registry = vm.$options.filters filters.forEach(function (f) { var def = vm.$options.filters[f.name] _.assertAsset(def, 'filter', f.name) if (!def) return var args = f.args var reader, writer if (typeof def === 'function') { reader = def } else { reader = def.read writer = def.write } if (reader) { if (!res.read) res.read = [] res.read.push(function (value) { return args ? reader.apply(vm, [value].concat(args)) : reader.call(vm, value) }) } if (writer) { if (!res.write) res.write = [] res.write.push(function (value, oldVal) { return args ? writer.apply(vm, [value, oldVal].concat(args)) : writer.call(vm, value, oldVal) }) } }) return res } /** * Apply filters to a value * * @param {*} value * @param {Array} filters * @param {Vue} vm * @param {*} oldVal * @return {*} */ exports.applyFilters = function (value, filters, vm, oldVal) { if (!filters) { return value } for (var i = 0, l = filters.length; i < l; i++) { value = filters[i].call(vm, value, oldVal) } return value }
Version data entries
5 entries across 5 versions & 1 rubygems