
Security News
Risky Biz Podcast: Making Reachability Analysis Work in Real-World Codebases
This episode explores the hard problem of reachability analysis, from static analysis limits to handling dynamic languages and massive dependency trees.
Stupid simple store library for mixin based state management in Vue.js
Vue
2.0.0+mapMutations
in my components.Vue
is already providing.Vuemix
only has one method: create
. Easy, right?
Vuemix.create(schema, store, as)
Parameter: schema
methods
this
context of the Vue
component itself; so, one is able to access component instance specific properties/methods.mixin
Vue
component like any other mixin.Object
.var SCHEMA = {
methods: {
updateMessage: function (store, value) {
store.state.value = value;
},
increment: function (store) {
console.log('Store method: increment');
store.methods.updateMessage(store.state.value + 1);
}
},
mixin: {
beforeMount: function () {
console.log('Mixin method: beforeMount');
},
methods: {
increment: function() {
console.log('Mixin method: increment');
this.test.value++;
}
}
}
};
Parameter: store
Object
.var store = {
value: 0
};
Parameter: as
Vue
component.String
.var name = 'test';
If you were write a small wrapper in ES6, it may look something like.
import Vuemix from 'vuemix';
function createTestStore() {
return {
value: 0
};
}
const GLOBAL_STORE = createTestStore();
const SCHEMA = {
methods: {
setValue({state}, value) {
store.value = value;
}
},
component: {
methods: {
setValue(value) {
console.log('Mixin method: setValue', value);
}
}
}
};
export default {
new(as) {
return Vuemix.create(SCHEMA, createTestStore(), as);
},
global(as) {
return Vuemix.create(SCHEMA, GLOBAL_STORE, as);
}
};
Then, use like this.
<template>
<span>Value: <span>{{myTest.value}}</span></span>
</template>
<script>
import TestStoreMixin from '/test/store/mixin';
// The store data will bind to the component as 'myTest'
const testStore = TestStoreMixin.global('myTest');
export default {
mixins: [testStore],
template: '#test',
methods: {
clicked() {
console.log(this.myTest.value); // 0
testStore.setValue(1);
console.log(this.myTest.value); // 1
}
}
};
</script>
Not a complex example but should give you an idea. This example is in the examples directory.
You can also view live here.
// Helper function for generating new test store state
function createTestStore() {
return {
value: 0
};
}
var GLOBAL_STORE = createTestStore();
var SCHEMA = {
// Worried about naming collisions from these methods and the methods being mixed in?
// The methods are attached to the mixin's prototype so `Vue` does not attach those
// methods to the component itself preventing name collisions! Nice!
methods: {
updateMessage: function (store, value) {
store.state.value = value;
},
increment: function (store) {
console.log('Store method: increment');
store.methods.updateMessage(store.state.value + 1);
}
},
mixin: {
beforeMount: function () {
console.log('Mixin method: beforeMount');
},
methods: {
increment: function() {
console.log('Mixin method: increment');
this.test.value++;
}
}
}
};
// Your state is linked by object references.
// Notice, we explicitly pass in the global or a new test `store` object.
// By doing this, it keeps how you manage state extremely liberal.
// Global Store
var globalStore = Vuemix.create(SCHEMA, GLOBAL_STORE, 'test');
// Instance Store
var instanceStore = Vuemix.create(SCHEMA, createTestStore(), 'test');
Vue.component('test', {
mixins: [globalStore],
template: '#test',
data: function () {
return {
other: null
};
},
methods: {
clicked: function () {
// RECOMMENDED: Update global state via store methods
globalStore.updateMessage(1);
}
}
});
Vue.component('test2', {
mixins: [globalStore],
template: '#test',
data: function () {
return {
other: null
};
},
methods: {
clicked: function () {
// NOT RECOMMENDED: Update global state directly
this.test.value = 2;
}
}
});
Vue.component('test3', {
mixins: [instanceStore],
template: '#test',
computed: {
other: function () {
return this.test.value + 1;
}
},
methods: {
clicked: function () {
instanceStore.increment();
}
}
});
FAQs
Stupid simple store library for mixin based state management in Vue.js
The npm package vuemix receives a total of 1 weekly downloads. As such, vuemix popularity was classified as not popular.
We found that vuemix 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
This episode explores the hard problem of reachability analysis, from static analysis limits to handling dynamic languages and massive dependency trees.
Security News
/Research
Malicious Nx npm versions stole secrets and wallet info using AI CLI tools; Socket’s AI scanner detected the supply chain attack and flagged the malware.
Security News
CISA’s 2025 draft SBOM guidance adds new fields like hashes, licenses, and tool metadata to make software inventories more actionable.