vue-deepset
Advanced tools
Comparing version 0.1.0 to 0.2.0
97
index.js
@@ -10,2 +10,8 @@ 'use strict'; | ||
var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { | ||
return typeof obj; | ||
} : function (obj) { | ||
return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; | ||
}; | ||
/* | ||
@@ -27,2 +33,13 @@ * @author Branden Horiuchi <bhoriuchi@gmail.com> | ||
/** | ||
* joins 2 paths | ||
* @param base | ||
* @param path | ||
* @returns {string} | ||
*/ | ||
function pathJoin(base, path) { | ||
var connector = path.match(/^\[/) ? '' : '.'; | ||
return '' + (base ? base : '') + (base ? connector : '') + path; | ||
} | ||
/** | ||
* generates an array of paths to use when creating an abstracted object | ||
@@ -71,3 +88,2 @@ * @param obj | ||
var fields = _.isArray(path) ? path : _.toPath(path); | ||
for (var i = 0; i < fields.length; i++) { | ||
@@ -120,19 +136,33 @@ var prop = fields[i]; | ||
if (!_.isString(vuexPath)) throw new Error('VueDeepSet: invalid vuex path string'); | ||
var model = {}; | ||
var obj = _.get(this.$store.state, vuexPath); | ||
_.forEach(getPaths(obj), function (path) { | ||
var connector = path.match(/^\[/) ? '' : '.'; | ||
var propPath = '' + vuexPath + connector + path; | ||
Object.defineProperty(model, path, { | ||
configurable: true, | ||
enumerable: true, | ||
get: function get() { | ||
return _.get(_this.$store.state, propPath); | ||
if ((typeof Proxy === 'undefined' ? 'undefined' : _typeof(Proxy)) === undefined) { | ||
var model = {}; | ||
var obj = _.get(this.$store.state, vuexPath); | ||
_.forEach(getPaths(obj), function (path) { | ||
var propPath = pathJoin(vuexPath, path); | ||
Object.defineProperty(model, path, { | ||
configurable: true, | ||
enumerable: true, | ||
get: function get$$1() { | ||
return _.get(_this.$store.state, propPath); | ||
}, | ||
set: function set$$1(value) { | ||
vuexSet.call(_this, propPath, value); | ||
} | ||
}); | ||
}); | ||
return model; | ||
} else { | ||
return new Proxy(_.get(this.$store.state, vuexPath, this.$store.state), { | ||
get: function get$$1(target, property) { | ||
return _.get(_this.$store.state, pathJoin(vuexPath, property)); | ||
}, | ||
set: function set(value) { | ||
vuexSet.call(_this, propPath, value); | ||
set: function set$$1(target, property, value) { | ||
vuexSet.call(_this, pathJoin(vuexPath, property), value); | ||
}, | ||
has: function has(target, property) { | ||
return true; | ||
} | ||
}); | ||
}); | ||
return model; | ||
} | ||
} | ||
@@ -149,16 +179,31 @@ | ||
if (!_.isObject(obj)) throw new Error('VueDeepSet: invalid object'); | ||
var model = {}; | ||
_.forEach(getPaths(obj), function (path) { | ||
Object.defineProperty(model, path, { | ||
configurable: true, | ||
enumerable: true, | ||
get: function get() { | ||
return _.get(obj, path); | ||
if (typeof Proxy === 'undefined') { | ||
var model = {}; | ||
_.forEach(getPaths(obj), function (path) { | ||
Object.defineProperty(model, path, { | ||
configurable: true, | ||
enumerable: true, | ||
get: function get$$1() { | ||
return _.get(obj, path); | ||
}, | ||
set: function set$$1(value) { | ||
vueSet.call(_this2, obj, path, value); | ||
} | ||
}); | ||
}); | ||
return model; | ||
} else { | ||
return new Proxy(obj, { | ||
get: function get$$1(target, property) { | ||
return _.get(target, property); | ||
}, | ||
set: function set(value) { | ||
vueSet.call(_this2, obj, path, value); | ||
set: function set$$1(target, property, value) { | ||
vueSet.call(_this2, target, property, value); | ||
}, | ||
has: function has(target, property) { | ||
return true; | ||
} | ||
}); | ||
}); | ||
return model; | ||
} | ||
} | ||
@@ -165,0 +210,0 @@ |
{ | ||
"name": "vue-deepset", | ||
"version": "0.1.0", | ||
"version": "0.2.0", | ||
"description": "Deep set Vue.js objects", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -8,2 +8,4 @@ # vue-deepset | ||
**Note** `vueModel` and `vuexModel` use [Proxy](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Proxy) objects if supported by the browser and fallback to an object with generated fields based on the target object. Because of this, it is always best to pre-define the properties of an object. | ||
### Examples | ||
@@ -10,0 +12,0 @@ |
@@ -11,2 +11,8 @@ (function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.VueDeepSet = f()}})(function(){var define,module,exports;return (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){ | ||
var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { | ||
return typeof obj; | ||
} : function (obj) { | ||
return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; | ||
}; | ||
/* | ||
@@ -28,2 +34,13 @@ * @author Branden Horiuchi <bhoriuchi@gmail.com> | ||
/** | ||
* joins 2 paths | ||
* @param base | ||
* @param path | ||
* @returns {string} | ||
*/ | ||
function pathJoin(base, path) { | ||
var connector = path.match(/^\[/) ? '' : '.'; | ||
return '' + (base ? base : '') + (base ? connector : '') + path; | ||
} | ||
/** | ||
* generates an array of paths to use when creating an abstracted object | ||
@@ -72,3 +89,2 @@ * @param obj | ||
var fields = _.isArray(path) ? path : _.toPath(path); | ||
for (var i = 0; i < fields.length; i++) { | ||
@@ -121,19 +137,33 @@ var prop = fields[i]; | ||
if (!_.isString(vuexPath)) throw new Error('VueDeepSet: invalid vuex path string'); | ||
var model = {}; | ||
var obj = _.get(this.$store.state, vuexPath); | ||
_.forEach(getPaths(obj), function (path) { | ||
var connector = path.match(/^\[/) ? '' : '.'; | ||
var propPath = '' + vuexPath + connector + path; | ||
Object.defineProperty(model, path, { | ||
configurable: true, | ||
enumerable: true, | ||
get: function get() { | ||
return _.get(_this.$store.state, propPath); | ||
if ((typeof Proxy === 'undefined' ? 'undefined' : _typeof(Proxy)) === undefined) { | ||
var model = {}; | ||
var obj = _.get(this.$store.state, vuexPath); | ||
_.forEach(getPaths(obj), function (path) { | ||
var propPath = pathJoin(vuexPath, path); | ||
Object.defineProperty(model, path, { | ||
configurable: true, | ||
enumerable: true, | ||
get: function get$$1() { | ||
return _.get(_this.$store.state, propPath); | ||
}, | ||
set: function set$$1(value) { | ||
vuexSet.call(_this, propPath, value); | ||
} | ||
}); | ||
}); | ||
return model; | ||
} else { | ||
return new Proxy(_.get(this.$store.state, vuexPath, this.$store.state), { | ||
get: function get$$1(target, property) { | ||
return _.get(_this.$store.state, pathJoin(vuexPath, property)); | ||
}, | ||
set: function set(value) { | ||
vuexSet.call(_this, propPath, value); | ||
set: function set$$1(target, property, value) { | ||
vuexSet.call(_this, pathJoin(vuexPath, property), value); | ||
}, | ||
has: function has(target, property) { | ||
return true; | ||
} | ||
}); | ||
}); | ||
return model; | ||
} | ||
} | ||
@@ -150,16 +180,31 @@ | ||
if (!_.isObject(obj)) throw new Error('VueDeepSet: invalid object'); | ||
var model = {}; | ||
_.forEach(getPaths(obj), function (path) { | ||
Object.defineProperty(model, path, { | ||
configurable: true, | ||
enumerable: true, | ||
get: function get() { | ||
return _.get(obj, path); | ||
if (typeof Proxy === 'undefined') { | ||
var model = {}; | ||
_.forEach(getPaths(obj), function (path) { | ||
Object.defineProperty(model, path, { | ||
configurable: true, | ||
enumerable: true, | ||
get: function get$$1() { | ||
return _.get(obj, path); | ||
}, | ||
set: function set$$1(value) { | ||
vueSet.call(_this2, obj, path, value); | ||
} | ||
}); | ||
}); | ||
return model; | ||
} else { | ||
return new Proxy(obj, { | ||
get: function get$$1(target, property) { | ||
return _.get(target, property); | ||
}, | ||
set: function set(value) { | ||
vueSet.call(_this2, obj, path, value); | ||
set: function set$$1(target, property, value) { | ||
vueSet.call(_this2, target, property, value); | ||
}, | ||
has: function has(target, property) { | ||
return true; | ||
} | ||
}); | ||
}); | ||
return model; | ||
} | ||
} | ||
@@ -166,0 +211,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
21896
421
217