Skip to content
This repository was archived by the owner on Jan 26, 2023. It is now read-only.

Commit e7d6b0e

Browse files
cilicemarudor
authored andcommitted
chore: use prettier (#73)
1 parent d799d9e commit e7d6b0e

19 files changed

+357
-274
lines changed

.circleci/config.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ workflows:
9292
check:
9393
triggers:
9494
- schedule:
95-
cron: "0 20 * * *"
95+
cron: '0 20 * * *'
9696
filters:
9797
branches:
9898
only: master

.editorconfig

-10
This file was deleted.

.huskyrc

+1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
{
22
"hooks": {
3+
"pre-commit": "pretty-quick --staged",
34
"commit-msg": "commitlint -E HUSKY_GIT_PARAMS",
45
"pre-push": "npm run lint"
56
}

.prettierrc

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"semi": false,
3+
"trailingComma": "all",
4+
"quoteProps": "consistent",
5+
"singleQuote": true
6+
}

README.md

+60-77
Original file line numberDiff line numberDiff line change
@@ -3,23 +3,24 @@
33
[![Test Coverage](https://api.codeclimate.com/v1/badges/635869dc6220b29b1aa6/test_coverage)](https://codeclimate.com/github/sumcumo/vue-states/test_coverage)
44

55
# Vue States
6-
*Vue States is a state management system for Vue.js.*
6+
7+
_Vue States is a state management system for Vue.js._
78

89
Checkout the examples at https://github.com/JohannesLamberts/vue-states-examples.
910

1011
You might want to choose to use Vue States for:
1112

1213
- **Simplicity** <br />Just `this.MyModel.key` and `this.MyModel.update(payload)`. No huge API, that exposes implementation details like `state, getters, commit, dispatch`.<br />Hot Module Replacement and Lazy-Loading made easy.
13-
- **Flexible scope**<br />It is designed to support application-wide and local state, and can still be hydrated from SSR or localStorage.
14+
- **Flexible scope**<br />It is designed to support application-wide and local state, and can still be hydrated from SSR or localStorage.
1415
- **Learning & refactoring**<br />The state is composed of Vue components. That means: almost no new APIs and patterns to learn, plus seamless refactoring of your application.
1516
- **Power**<br />All plugins and native Vue capabilities are accessible by design, without any configuration ( `this.$router, this.$apollo, created()...` ).
1617
- **[History](#history)**<br />In combination with [Vue History](https://github.com/sumcumo/vue-history) you get a detailed view of what's going on, even for complex scenarios, async processes, error tracking and deeply nested call chains.
1718

18-
*This package was released just recently. Feedback is highly welcome.*
19+
_This package was released just recently. Feedback is highly welcome._
1920

2021
## Installation
2122

22-
The plugin can be installed without any further options:
23+
The plugin can be installed without any further options:
2324

2425
```javascript
2526
import VueStates from '@sum.cumo/vue-states'
@@ -29,23 +30,20 @@ Vue.use(VueStates)
2930
...or with additional configuration:
3031

3132
```javascript
32-
Vue.use(
33-
VueStates,
34-
{
35-
// equal to Vue mixins, will be applied to every created model
36-
mixins: [],
37-
38-
// a models state will be restored
39-
// if an old match (same name and modelId) is found
40-
// can be used to preserve state during hot module replacement 🚀
41-
// default: false
42-
restoreOnReplace: process.env.NODE_ENV === 'development',
43-
44-
// registers models on the $root instance, same as
45-
// const app = new Vue({ models: globalModels })
46-
globalModels,
47-
}
48-
)
33+
Vue.use(VueStates, {
34+
// equal to Vue mixins, will be applied to every created model
35+
mixins: [],
36+
37+
// a models state will be restored
38+
// if an old match (same name and modelId) is found
39+
// can be used to preserve state during hot module replacement 🚀
40+
// default: false
41+
restoreOnReplace: process.env.NODE_ENV === 'development',
42+
43+
// registers models on the $root instance, same as
44+
// const app = new Vue({ models: globalModels })
45+
globalModels,
46+
})
4947
```
5048

5149
## Getting started
@@ -64,31 +62,30 @@ export default {
6462
products: [],
6563
}
6664
},
67-
68-
// created / destroy hooks are invoked
65+
66+
// created / destroy hooks are invoked
6967
created() {
7068
this.stage = 'created'
7169
this.loadProducts()
7270
},
73-
71+
7472
// vuex mutations and actions become just methods
7573
methods: {
7674
async loadProducts() {
7775
this.saveProducts(await this.$api.loadProducts())
7876
},
7977
saveProducts(products) {
8078
this.products = products
81-
}
79+
},
8280
},
83-
81+
8482
// vuex getters become computed
8583
computed: {
8684
stageUppercase() {
8785
return this.stage.toUpperCase()
8886
},
8987
},
9088
}
91-
9289
```
9390

9491
### Hosting
@@ -100,14 +97,13 @@ It is available in the hosting component itself and any child component, that in
10097
import App from '@/models/example'
10198

10299
export default {
103-
104100
name: 'ExampleHost',
105-
101+
106102
models: {
107103
// 'App' becomes the models name and the key to reference it
108104
App,
109105
},
110-
106+
111107
template: `
112108
<div>
113109
<!--
@@ -124,13 +120,10 @@ export default {
124120

125121
```javascript
126122
export default {
127-
128123
name: 'ExampleChild',
129-
130-
injectModels: [
131-
'App',
132-
],
133-
124+
125+
injectModels: ['App'],
126+
134127
template: `
135128
<div>
136129
<!-- properties are reactive -->
@@ -141,10 +134,9 @@ export default {
141134
}
142135
```
143136

137+
## History
144138

145-
## History
146-
147-
To keep track of what happens inside the models can check out [Vue History](https://github.com/sumcumo/vue-history),
139+
To keep track of what happens inside the models can check out [Vue History](https://github.com/sumcumo/vue-history),
148140
a package that was developed alongside Vue States but not only works for models but for any Vue component.
149141

150142
After installing Vue History you can enable it for all models by setting the `history: true` option:
@@ -155,19 +147,14 @@ import VueStates from '@sum.cumo/vue-states'
155147

156148
Vue.use(VueHistory)
157149

158-
Vue.use(
159-
VueStates,
160-
{ mixins: [ { history: true } ] }
161-
)
150+
Vue.use(VueStates, { mixins: [{ history: true }] })
162151
```
163152

164-
165-
166153
## State export/import
167154

168155
State can be exported from and imported into the root model registry.
169156
The imported state will be used when initializing models with matching name and modelId.
170-
The state must therefore be imported *before* the model is initialized.
157+
The state must therefore be imported _before_ the model is initialized.
171158

172159
```javascript
173160
const exported = app.$modelRegistry.exportState()
@@ -182,29 +169,27 @@ The export can be configured to filter which models will be included in the expo
182169

183170
```javascript
184171
const exported = app.$modelRegistry.exportState({
185-
186172
// default: true,
187-
// set to false to exclude all models,
188-
// where `exportState` is undefined
173+
// set to false to exclude all models,
174+
// where `exportState` is undefined
189175
filterDefault: false,
190-
176+
191177
// context will be passed to exportState callbacks
192178
context: {
193179
isLocalStorageExport: true,
194180
},
195-
196181
})
197182
```
198183

199-
Models may include an `exportState` option, which must be
184+
Models may include an `exportState` option, which must be
200185
either a function or a boolean.
201186

202187
```
203188
export default {
204189
name: 'UserModel',
205190
exportState(context) {
206191
return context.isLocalStorageExport
207-
// vm can be accessed from withing the callback
192+
// vm can be accessed from withing the callback
208193
&& this.isLoggedIn
209194
}
210195
}
@@ -226,11 +211,12 @@ Object.defineProperty(context, 'vueModelState', {
226211
return app.$modelRegistry.exportState()
227212
},
228213
})
229-
```
214+
```
230215

231216
```html
232217
<!-- index.html -->
233-
{{{ renderState({ contextKey: 'vueModelState', windowKey: '__VUE_STATES__' }) }}}
218+
{{{ renderState({ contextKey: 'vueModelState', windowKey: '__VUE_STATES__' })
219+
}}}
234220
```
235221

236222
```javascript
@@ -239,7 +225,7 @@ import { Registry } from '@sum.cumo/vue-states'
239225

240226
export default async function createApp() {
241227
// ...
242-
228+
243229
const modelRegistry = new Registry()
244230

245231
if (typeof window !== 'undefined' && window.__VUE_STATES__) {
@@ -262,20 +248,20 @@ For import/export to work you will need to provide an id to further identify the
262248

263249
```javascript
264250
export default modelId => ({
265-
// the combination of name and modelId must be unique at any given time
266-
modelId,
251+
// the combination of name and modelId must be unique at any given time
252+
modelId,
267253

268-
data() {
269-
return {
270-
counter: 0,
271-
}
272-
},
273-
274-
methods: {
275-
increment() {
276-
this.counter += 1
277-
},
254+
data() {
255+
return {
256+
counter: 0,
257+
}
258+
},
259+
260+
methods: {
261+
increment() {
262+
this.counter += 1
278263
},
264+
},
279265
})
280266
```
281267

@@ -287,16 +273,16 @@ export default {
287273
someIdentifier: {
288274
type: String,
289275
required: true,
290-
}
276+
},
291277
},
292-
293-
// you may also pass a function that is evaluated in the created hook
278+
279+
// you may also pass a function that is evaluated in the created hook
294280
// and receives the hosting Vue component as context
295281
models() {
296282
return {
297283
Counter: createCounter(this.someIdentifier),
298284
}
299-
}
285+
},
300286
}
301287
```
302288

@@ -305,10 +291,7 @@ export default {
305291
Nuxt.js gets confused by the models attached to the component tree. The errors can be resolved by adding `abtract: true` to all models (which however makes them invisible in the developer tools).
306292

307293
```javascript
308-
Vue.use(
309-
VueStates,
310-
{ mixins: [ { abstract: true } ] }
311-
)
294+
Vue.use(VueStates, { mixins: [{ abstract: true }] })
312295
```
313296

314297
## License
@@ -321,6 +304,6 @@ Licensed under the Apache License, Version 2.0 (the “License”); you may not
321304

322305
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an “AS IS” BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
323306

324-
----
307+
---
325308

326309
[Learn more about sum.cumo](https://www.sumcumo.com/en) and [work on open source projects](https://www.sumcumo.com/jobs), too!

build/rollup.config.base.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,5 @@ import typescript from 'rollup-plugin-typescript2'
33
export default {
44
input: 'src/index.ts',
55
plugins: [typescript()],
6-
external: ['vue-class-component']
6+
external: ['vue-class-component'],
77
}

build/rollup.config.browser.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ const config = Object.assign({}, base, {
88
name: 'VueStates',
99
exports: 'named',
1010
globals: {
11-
'vue-class-component': 'vueClassComponent'
12-
}
11+
'vue-class-component': 'vueClassComponent',
12+
},
1313
},
1414
})
1515

build/rollup.config.umd.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ const config = Object.assign({}, base, {
77
name: 'VueStates',
88
exports: 'named',
99
globals: {
10-
'vue-class-component': 'vueClassComponent'
11-
}
10+
'vue-class-component': 'vueClassComponent',
11+
},
1212
},
1313
})
1414

0 commit comments

Comments
 (0)