spoki4 / vuexus Goto Github PK
View Code? Open in Web Editor NEWHelpers and boilerplate reducers
Helpers and boilerplate reducers
Установка:
npm install @vuexus/vue
Использование:
import Vuexus from '@vuexus/vue'
Vue.use(new Vuexus())
Описание модуля:
@Module
export class PageModule {
data = []
@SubModule
subModule = new SubModuleClass()
@Module(ParentModule)
parentModule!: ParentModule
get getMyData() {
return this.data.map(...transform...)
}
@Mutation setData(data) {this.data = data}
@Action async loadSomeData() {
const response = await dataLoadFunc()
this.setData(response)
getStore(AuthModule).logout()
}
// Вызывается автоматически в соответствующем жизненом цикле
@Hook.Created created(options) {
// options = {params: {}, query: {}, cookies: {}}
this.loadSomeData()
}
// Вызывается автоматически при изменении query параметров
@Hook.QueryChanged onQueryUpdated(options) {
// options = {params: {}, query: {}, cookies: {}}
}
}
Использование в vue Parent:
<template>
<div class="wrapper">
<div v-for="item in store.getMyData">
</div>
<child />
</div>
<template>
<script>
export default {
name: 'parent',
stores: {
store: PageModule
}
}
</script>
Использование в vue Child:
<script>
export default {
name: 'child',
stores: {
parentStore: PageModule // The same instance, gets from provide/inject
}
}
</script>
Тесты:
const instance = createTestModule(ModuleClass)
instance.setData([1,2,3])
assert(instance.getData(), [1,2,3])
@Store({ reset: true })
store1 -> component1.beforeCreate -> store1.register -> store1.usages.push(component1)
store1 -> component2.beforeCreate -> store1.usages.push(component2)
component1.destoryed -> store1.usages.remove(component1)
component2.destoryed -> store1.usages.remove(component2) -> store1.usages.length === 0 -> store1.unregister
Варианты:
When we use terser in project, that compress our classes and it can be has names as 'a' or 'b' or 'f' and more...
If our class names collide, we cannot register vuex module with same name.
It can be break production builds.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.