Skip to content

Commit c030e76

Browse files
committed
Updated to vuex 1.0.0-rc.2
1 parent 0296a60 commit c030e76

File tree

6 files changed

+86
-66
lines changed

6 files changed

+86
-66
lines changed

.meteor/versions

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ akryum:vue-less@0.0.3
1414
akryum:vue-router@0.1.2
1515
akryum:vue-sass@0.0.1
1616
akryum:vue-stylus@0.0.1
17-
akryum:vuex@0.2.2
17+
akryum:vuex@0.3.0
1818
allow-deny@1.0.5
1919
apollo@0.0.3
2020
autoupdate@1.2.10

packages/vuex/CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
# Changelog
22

3+
## 0.3.0 - 2016/07/06
4+
5+
- Updated to vuex 1.0.0-rc.2 (some breaking changes may apply, see [release notes](https://github.com/vuejs/vuex/releases/tag/v1.0.0-rc))
6+
- (BREAKING CHANGE) Store module property `root` has been renamed to `$root`.
7+
- Submodules can now contain nested submodules.
8+
- New module property `$parent`.
9+
310
## 0.2.2 - 2016/07/01
411

512
- Fixed a leak related to the tracker `watch()` option.

packages/vuex/README.md

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -473,6 +473,29 @@ export default {
473473
}
474474
```
475475

476+
### Nested submodules
477+
478+
You can add nested submodules to your submodules with the same `addModule()` method as the root module:
479+
480+
```javascript
481+
// Inside the 'forum' submodule
482+
// Add a nested submodule
483+
import thread from './thread';
484+
subModule.addModule(thread);
485+
```
486+
487+
In your vue components, you can access the nested submodules by calling them on their parent module:
488+
489+
```javascript
490+
export default {
491+
vuex: ({forum}) => ({
492+
trackers: {
493+
selectedThread: forum.thread.trackers.getSelectedThread
494+
}
495+
})
496+
}
497+
```
498+
476499
### Meteor data integration
477500

478501
To use meteor reactive data with your store, use *trackers* on your module with the `addTrackers(map)` method:
@@ -634,12 +657,12 @@ Example for the tracker we created above:
634657
export default {
635658
methods: {
636659
needTracker() {
637-
// this.$store.root.<submodule>.trackers.<tracker_name>.addClient();
638-
this.$store.root.forum.trackers.threads.addClient();
660+
// this.$store.$root.<submodule>.trackers.<tracker_name>.addClient();
661+
this.$store.$root.forum.trackers.threads.addClient();
639662
},
640663
noLongerNeedTracker() {
641-
// this.$store.root.<submodule>.trackers.<tracker_name>.removeClient();
642-
this.$store.root.forum.trackers.threads.removeClient();
664+
// this.$store.$root.<submodule>.trackers.<tracker_name>.removeClient();
665+
this.$store.$root.forum.trackers.threads.removeClient();
643666
}
644667
}
645668
}

packages/vuex/client/client.js

Lines changed: 49 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ export class StoreSubModule {
1919
this._trackers = {};
2020
this._meteorData = {};
2121
this._trackerHandlers = {};
22+
this._modules = {};
2223
this._vm = null;
2324
this._exported = false;
2425
}
@@ -48,8 +49,15 @@ export class StoreSubModule {
4849
_.merge(this._trackers, map);
4950
}
5051

52+
addModule(module) {
53+
this._checkExported();
54+
this[module.name] = this._modules[module.name] = module;
55+
module.$parent = this;
56+
module.$root = this.$root;
57+
}
58+
5159
getState(state) {
52-
return state[this.name];
60+
return this.$parent.getState(state)[this.name];
5361
}
5462

5563
callMethod(...args) {
@@ -83,6 +91,23 @@ export class StoreSubModule {
8391
});
8492
}
8593

94+
_generateExportOptions() {
95+
// Modules
96+
let modules = {};
97+
for (let m in this._modules) {
98+
let module = this._modules[m];
99+
modules[module.name] = module._generateExportOptions();
100+
}
101+
102+
const options = {
103+
state: this._state,
104+
mutations: this._mutations,
105+
modules
106+
};
107+
108+
return options;
109+
}
110+
86111
_checkExported() {
87112
if(this._exported) {
88113
throw new Error(`The store has been exported, you can't change the modules anymore.`);
@@ -99,6 +124,10 @@ export class StoreSubModule {
99124
this._vm = new Vue({
100125
data: this._meteorData
101126
});
127+
128+
for (let m in this._modules) {
129+
this._modules[m]._createTrackers();
130+
}
102131
}
103132

104133
_setStore(store) {
@@ -108,12 +137,20 @@ export class StoreSubModule {
108137
}
109138

110139
this._exported = true;
140+
141+
for (let m in this._modules) {
142+
this._modules[m]._setStore(store);
143+
}
111144
}
112145

113146
_processGetters() {
114147
for (let g in this._getters) {
115148
this.getters[g] = this._addGetter(this._getters[g]);
116149
}
150+
151+
for (let m in this._modules) {
152+
this._modules[m]._processGetters();
153+
}
117154
}
118155

119156
_addGetter(getter) {
@@ -126,6 +163,10 @@ export class StoreSubModule {
126163
for (let g in this._actions) {
127164
this.actions[g] = this._addAction(this._actions[g]);
128165
}
166+
167+
for (let m in this._modules) {
168+
this._modules[m]._processActions();
169+
}
129170
}
130171

131172
_addAction(action) {
@@ -146,82 +187,31 @@ export class StoreSubModule {
146187
export class StoreModule extends StoreSubModule {
147188
constructor() {
148189
super("root");
149-
this._modules = {};
150-
this.root = this;
190+
this.$root = this;
151191
}
152192

153193
getState(state) {
154194
return state;
155195
}
156196

157-
addModule(module) {
158-
this._checkExported();
159-
this[module.name] = this._modules[module.name] = module;
160-
module.root = this;
161-
}
162-
163197
exportStore() {
164-
198+
// Process options
165199
this._processGetters();
166200
this._processActions();
167-
168201
this._createTrackers();
169202

170-
// Modules
171-
let modules = {};
172-
for (let m in this._modules) {
173-
let module = this._modules[m];
174-
modules[module.name] = {
175-
state: module._state,
176-
mutations: module._mutations
177-
}
178-
}
179-
180-
let options = {
181-
state: this._state,
182-
mutations: this._mutations,
183-
modules
184-
};
185-
let store = new ExtendedStore(this, options);
186-
203+
// Create native vuex store
204+
let store = new ExtendedStore(this, this._generateExportOptions());
187205
this._setStore(store);
188206

189207
return store;
190208
}
191-
192-
_createTrackers() {
193-
super._createTrackers();
194-
for (let m in this._modules) {
195-
this._modules[m]._createTrackers();
196-
}
197-
}
198-
199-
_setStore(store) {
200-
super._setStore(store);
201-
for (let m in this._modules) {
202-
this._modules[m]._setStore(store);
203-
}
204-
}
205-
206-
_processGetters() {
207-
super._processGetters();
208-
for (let m in this._modules) {
209-
this._modules[m]._processGetters();
210-
}
211-
}
212-
213-
_processActions() {
214-
super._processActions();
215-
for (let m in this._modules) {
216-
this._modules[m]._processActions();
217-
}
218-
}
219209
}
220210

221211
class ExtendedStore extends Vuex.Store {
222-
constructor(root, options) {
212+
constructor($root, options) {
223213
super(options);
224-
this.root = root;
214+
this.$root = $root;
225215
}
226216
}
227217

@@ -376,7 +366,7 @@ const PreVuexPlugin = {
376366
if (!store && options.parent && options.parent.$store) {
377367
store = options.parent.$store
378368
}
379-
options.vuex = vuexCb(store.root);
369+
options.vuex = vuexCb(store.$root);
380370
}
381371
}
382372
}

packages/vuex/npm.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
22
"devDependencies": {
3-
"vuex": "^0.8.0"
3+
"vuex": "^1.0.0-rc.2"
44
}
55
}

packages/vuex/package.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Package.describe({
22
name: 'akryum:vuex',
3-
version: '0.2.2',
3+
version: '0.3.0',
44
summary: 'State management with vuex for Meteor',
55
git: 'https://github.com/Akryum/meteor-vue-component',
66
documentation: 'README.md'

0 commit comments

Comments
 (0)