Skip to content

Commit e13c12b

Browse files
committed
update docs
1 parent 2473dc5 commit e13c12b

File tree

1 file changed

+96
-31
lines changed

1 file changed

+96
-31
lines changed

README.md

Lines changed: 96 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,12 @@
66
- DOM-based, mutates in place
77
- Driven by `@vue/reactivity`
88

9+
## Status
10+
11+
- This is pretty new. There are probably bugs and there might still be API changes, so **use at your own risk.**
12+
13+
- The issue list is intentionally disabled because I have higher priority things to focus on for now and don't want to be distracted. If you found a bug, you'll have to either workaround it or submit a PR to fix it yourself. Feature requests are also unlikely to be accepted at this time - the scope of this project is intentionally kept to a bare minimum.
14+
915
## Usage
1016

1117
```html
@@ -29,7 +35,7 @@ If you don't want the auto init, remove the `init` attribute and move the script
2935
```html
3036
<script src="https://unpkg.com/petite-vue"></script>
3137
<script>
32-
PetiteVue.createapp().mount()
38+
PetiteVue.createApp().mount()
3339
</script>
3440
```
3541

@@ -42,6 +48,58 @@ Or, use the ES modules build:
4248
<script>
4349
```
4450
51+
### Root Scope
52+
53+
The `createApp` function accepts a data object that serves as the root scope for all expressions. This can be used for simple global state management:
54+
55+
```html
56+
<script type="module">
57+
import { createApp } from 'https://unpkg.com/petite-vue?module'
58+
59+
createApp({
60+
// exposed to all expressions
61+
count: 0,
62+
// getters
63+
get plusOne() {
64+
return this.count + 1
65+
},
66+
// methods
67+
increment() {
68+
this.count++
69+
}
70+
}).mount()
71+
</script>
72+
73+
<!-- v-scope value can be omitted -->
74+
<div v-scope>
75+
<p>{{ count }}</p>
76+
<p>{{ plusOne }}</p>
77+
<button @click="increment">increment</button>
78+
</div>
79+
```
80+
81+
Note `v-scope` doesn't need to have a value here and simply serves as a hint for `petite-vue` to process the element.
82+
83+
### Explicit Mount Target
84+
85+
You can specify a mount target (selector or element) to limit `petite-vue` to only that region of the page:
86+
87+
```js
88+
createApp().mount('#only-this-div')
89+
```
90+
91+
This also means you can have multiple `petite-vue` apps to control different regions on the same page:
92+
93+
```js
94+
createApp({
95+
// root scope for app one
96+
}).mount('#app1')
97+
98+
createApp({
99+
// root scope for app two
100+
}).mount('#app2')
101+
```
102+
45103
### Lifecycle Events
46104

47105
You can listen to the `mounted` and `unmounted` lifecycle events for each element:
@@ -67,36 +125,6 @@ Use `v-effect` to execute **reactive** inline statements:
67125

68126
The effect uses `count` which is a reactive data source, so it will re-run whenever `count` changes.
69127

70-
### Global Data
71-
72-
The `createApp` function accepts a data object that serves as the root scope for all expressions. This can be used for simple global state management:
73-
74-
```html
75-
<script type="module">
76-
import { createApp, reactive } from 'https://unpkg.com/petite-vue?module'
77-
78-
const store = reactive({
79-
count: 0,
80-
inc() {
81-
this.count++
82-
}
83-
})
84-
85-
createApp({
86-
// exposed to all expressions
87-
store
88-
}).mount()
89-
</script>
90-
91-
<div v-scope="{ localCount: 0 }">
92-
<p>Global {{ store.count }}</p>
93-
<button @click="store.inc">increment</button>
94-
95-
<p>Local {{ localCount }}</p>
96-
<button @click="localCount++">increment</button>
97-
</div>
98-
```
99-
100128
### Reusing Logic
101129

102130
There are no components, but logic can be shared across the app or encapsulated in setup-like functions:
@@ -125,6 +153,39 @@ There are no components, but logic can be shared across the app or encapsulated
125153
</div>
126154
```
127155

156+
### Global State Management
157+
158+
You can use the `reactive` method (re-exported from `@vue/reactivity`) to create global state singletons:
159+
160+
```html
161+
<script type="module">
162+
import { createApp, reactive } from 'https://unpkg.com/petite-vue?module'
163+
164+
const store = reactive({
165+
count: 0,
166+
inc() {
167+
this.count++
168+
}
169+
})
170+
171+
// manipulate it here
172+
store.inc()
173+
174+
createApp({
175+
// share it with app scopes
176+
store
177+
}).mount()
178+
</script>
179+
180+
<div v-scope="{ localCount: 0 }">
181+
<p>Global {{ store.count }}</p>
182+
<button @click="store.inc">increment</button>
183+
184+
<p>Local {{ localCount }}</p>
185+
<button @click="localCount++">increment</button>
186+
</div>
187+
```
188+
128189
### Custom Directives
129190

130191
Custom directives are also supported but with a different interface:
@@ -170,6 +231,10 @@ const html = ({ el, get, effect }) => {
170231
}
171232
```
172233

234+
## Examples
235+
236+
Check out the [examples directory](https://github.com/vuejs/petite-vue/tree/main/examples).
237+
173238
## Features
174239

175240
### `petite-vue` only

0 commit comments

Comments
 (0)