Gathering detailed insights and metrics for vue-data-proxy
Gathering detailed insights and metrics for vue-data-proxy
Gathering detailed insights and metrics for vue-data-proxy
Gathering detailed insights and metrics for vue-data-proxy
http-proxy-middleware
The one-liner node.js proxy middleware for connect, express, next.js and more
proxy-addr
Determine address of proxied request
http-proxy-agent
An HTTP(s) proxy `http.Agent` implementation for HTTP
proxy-from-env
Offers getProxyForUrl to get the proxy URL for a URL, respecting the *_PROXY (e.g. HTTP_PROXY) and NO_PROXY environment variables.
npm install vue-data-proxy
Module System
Min. Node Version
Typescript Support
Node Version
NPM Version
11 Stars
8 Commits
3 Watching
2 Branches
1 Contributors
Updated on 07 Feb 2024
JavaScript (100%)
Cumulative downloads
Total Downloads
Last day
0%
1
Compared to previous day
Last week
-93.8%
1
Compared to previous week
Last month
158.8%
44
Compared to previous month
Last year
-26.2%
347
Compared to previous year
2
This package provides vueDataProxy()
to generate a two-way bindable computed property from the result of a user's fetch
function (e.g. to retrieve the object from a Vuex store), that calls back a user's commit
function on any change on the object, even deeply nested.
Then, you get a very simple way of doing two-way binding with Vuex for use with v-model
This package, even if it doesn't limit its scope to the Vuejs / Vuex environment, was initially design to provide a simple way to get deep two way binding with Vuex. At the end, it can finally work with any type of datastore as long as they use Vue's reactivity system.
It can also be used without Vue at all as a starting point of a MVC system.
There are already a wide variety of utilities to deal with two-way bindings with Vuex store. However, none of them addresses the problem of dealing with nested substate, and having deep reactivity. For example, suppose you have this store :
.. code:: javascript
export default new Vuex.Store({
state: {
users : [
{ name : 'foo', category : 'bar' },
// ...
]
},
mutations : {
updateUser(state, {id, name, category}){
state.users[id].name = name;
state.users[id].category = category;
}
}
With the official Vuex' <https://vuex.vuejs.org/guide/forms.html#two-way-computed-property>
_ recommended way, you would have to declare two computed property, one for name
and one for category
, both calling the same mutation to update.
With Vuex's mapState <https://vuex.vuejs.org/guide/state.html#the-mapstate-helper>
_, it would be less verbose, but you'd still have to define a method and both the computed properties.
With vuex-bound <https://github.com/Vanilla-IceCream/vuex-bound#readme>
_, it would be even shorter, but still need you to define each property one by one.
vuex-dot <https://github.com/yarsky-tgz/vuex-dot#readme>
_ introduces an interresting way to do what the previous one does using a dot-synthax. However, it still does not handle the nested case.
This package addresses the problem of deep nested two-way binding by providing a function that generate a two-way bound computed property definition. Considering the previous example, you would simply write the following (let's suppose you write a .vue component) :
.. code:: xml
<template>
<input v-model="user.name" placeholder="user's name"/>
<input v-model="user.category" placeholder="user's category"/>
</template>
.. code:: javascript
import vueDataProxy from 'vue-data-proxy';
export default {
computed : {
...vueDataProxy({
user : {
fetch() { return this.$store.state.input[this.userId] },
commit(newVal){ this.$store.commit('updateUser', {id : this.userId, name : newVal.name, category : newVal.category}) },
}
}),
}
props : {
userId : Number,
},
},
On non-object proxied data, this generate a code equivalent to a simple two-way bound computed property.
Since the code is greatly inpired by Vue's reactivity system, it does have the same limitations. For example, it won't detect property addition nor array []
synthax assigment. However, you can use the array's method that Vue reactvity system is compatible with. (splice()
, push()
, pop()
, [...])
Another limitation, if you want the computed property nested attribute to be reactive, always access the computed property first. For example, the folowing wouldn't work :
.. code:: javascript
var alias // global scope alias
//[...]
methods : {
genAlias(){
alias = this.user.name;
}
computed : {
...vueDataProxy({
user : {
fetch() { return this.$store.state.input[this.userId] },
commit(newVal){ this.$store.commit('updateUser', {id : this.userId, name : newVal.name, category : newVal.category}) },
}
}),
name() { return alias } // not reactive because user is not a dependency
name2() { _ = this.user; return alias } // Reactive because even alias is accessed without accessing this.user, the _ variable marks this.user as a dependency, and force recomputation. (note you'd still need to regenerate the alias...)
}
.. code::
npm install --save vue-data-proxy
Wherever you need it:
.. code:: javascript
import vueDataProxy from 'vue-data-proxy'
The needed files are already provided in dist/
, but if you want to re build, simlply run :
.. code::
npm run build
.. code:: html
<script src="vueDataProxy.min.js"></script>
vueDataProxy(params)
params
is an object. Each key represents a proxy definition (a resulting computed property), and each associated value should be an object with the following fields :
- fetch
: A function with no arguments, this
representing the Vue local component instance. Should return the store object value.
- commit
: A function called at each modification (on the returned object from the computed property), taking the new value as parameter, and this representing the Vue local component.
This code is provided as-is, under the terms of the MIT license (see License file for more details).
A link to the original sources and contribution / pull request are welcome if you enjoy / use / contribute to this module ! :)
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
0 existing vulnerabilities detected
Reason
license file detected
Details
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
Found 0/8 approved changesets -- score normalized to 0
Reason
no SAST tool detected
Details
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
project is not fuzzed
Details
Reason
security policy file not detected
Details
Reason
branch protection not enabled on development/release branches
Details
Score
Last Scanned on 2024-11-25
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More