Security News
GitHub Removes Malicious Pull Requests Targeting Open Source Repositories
GitHub removed 27 malicious pull requests attempting to inject harmful code across multiple open source repositories, in another round of low-effort attacks.
vue-deepset
Advanced tools
Deep set Vue.js objects
Binding deeply nested data properties and vuex data to a form or component can be tricky. The following set of tools aims to simplify data bindings. Compatible with Vue 1.x
, Vue 2.x
, Vuex 1.x
, and Vuex 2.x
Note vueModel
and vuexModel
use 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.
Full examples can be found in the tests folder on the project repo
lodash@^4.0.0
vue@>=1.0.0
vuex@>=1.0.0
(optional)The modeling methods use lodash.toPath
format for path strings. Please ensure references use this format
v-model
to deeply nested objectsModel objects returned by $deepModel
, vueModel
, and vuexModel
are flat and use getter/setter methods to access and update deep properties on the target object. Because of this, when binding a deep model object using v-model
bracket notation should be used and the property value should be a path string. Using not notation past a single level object should be avoided.
<input type="text" v-model="model.prop1">
<input type="text" v-model="model['prop1.subprop']">
<input type="text" v-model="model['path.to["deep nested"]']">
import * as VueDeepSet from 'vue-deepset'
<script src='./node_modules/vue-deepset/vue-deepset.js'></script>
The easiest way to set up vue-deepset
is as a Vue.js plugin. The plugin adds instance methods $deepModel
, $vueSet
, and $vuexSet
. For vuex a mutation must be added (see vuex section).
When using ES6+ use import * as VueDeepSet from 'vue-deepset'
$deepModel ( obj:Object )
- for local vue objects$deepModel ( path:String )
- for vuex state properties; path to base object$vueSet (obj:Object, path:String, value:*)
$vuexSet (path:String, value:*)
html
<div id="app">
<input type="text" v-model="model['input1']">
<input type="text" v-model="model['path.to["deep nested"]']">
</div>
js
Vue.use(VueDeepSet)
var app = new Vue({
el: '#app',
store,
computed: {
model () {
return this.$deepModel(this.obj)
}
},
data: {
obj: {
input1: 'Hello World!',
path: {
to: {
'deep nested': 'Hello Vue!'
}
}
}
}
})
Form binding to vuex
using v-model
requires registering the provided VUEX_DEEP_SET
mutation. A convienience method extendMutation
has been provided.
html
<div id="app">
<input type="text" v-model="formData['message']">
</div>
js
var store = new Vuex.Store({
state: {
formData: {
message: 'Hello Vuex!'
}
},
mutations: VueDeepSet.extendMutation({
SOME_OTHER_MUTATION,
...
})
})
var app = new Vue({
el: '#app',
store,
computed: {
formData () {
return this.$deepModel('formData')
}
}
})
Converts a path string into the correct format for accessing deeply nested models
Deep sets a path with a value on a local data object so that is is reactive
Deep sets a path with a value in a vuex store so that it is reactive
Vuex mutation that should be registered when using vuexSet
Adds the VUEX_DEEP_SET
mutation to an optional hash of mutations and returns an updated hash of mutations
Creates an abstracted model with a set of flat properties that are generated from inspecting the objects properties so that deeply nested properties can be accessed as first level properties
The equivalent of vueModel
for vuex
. Path should point to the base object
Equivalent to vueModel
Equivalent to vuexModel
var store = new Vuex.Store({
state: {
formData: {
message: 'Hello Vuex!'
}
},
mutations: VueDeepSet.extendMutation()
})
var app = new Vue({
el: '#app',
store,
computed: {
vuexForm () {
return this.vuexModel('formData')
},
localForm () {
return this.vueModel(this.localForm)
}
},
methods: {
vueSet: VueDeepSet.vueSet,
vuexSet: VueDeepSet.vuexSet,
vueModel: VueDeepSet.vueModel,
vuexModel: VueDeepSet.vuexModel
},
data: {
localForm: {
message: 'Hello Vue!'
}
}
})
import { vueSet } from 'vue-deepset'
export default {
methods: {
vueSet: VueDeepSet.vueSet,
clearForm () {
this.vueSet(this.localForm, 'message', 'Modified')
}
},
data: {
localForm: {
message: 'Hello Vue!'
}
}
}
FAQs
Deep set Vue.js objects
The npm package vue-deepset receives a total of 645 weekly downloads. As such, vue-deepset popularity was classified as not popular.
We found that vue-deepset demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
GitHub removed 27 malicious pull requests attempting to inject harmful code across multiple open source repositories, in another round of low-effort attacks.
Security News
RubyGems.org has added a new "maintainer" role that allows for publishing new versions of gems. This new permission type is aimed at improving security for gem owners and the service overall.
Security News
Node.js will be enforcing stricter semver-major PR policies a month before major releases to enhance stability and ensure reliable release candidates.