Skip to content

Commit 72e8ac0

Browse files
authored
Update README.md
Updated docs a little to be more concise.
1 parent f2b93fa commit 72e8ac0

File tree

1 file changed

+40
-27
lines changed

1 file changed

+40
-27
lines changed

README.md

Lines changed: 40 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@ This is just a simple wrapper around [js-simple-events](https://github.com/kaska
77

88
And it's really light - ~1kb in size!
99

10-
## Methods
10+
## API
11+
12+
### Methods
1113

1214
Method | Params | Description
1315
-------- | ----------------- | ----------------------------------------------------------------
@@ -23,6 +25,26 @@ Method | Params | Description
2325
`vm.$events.$off` | `event, callback` | _Alias for `off`_
2426
`vm.$events.remove` | `event, callback` | _Alias for `off`_
2527

28+
### Component Options
29+
30+
```js
31+
/// Some component.vue
32+
export default {
33+
// registers event handlers on 'created'
34+
on: {
35+
handler(arg) {
36+
console.log(args)
37+
}
38+
},
39+
// Same as previous, but is called only once.
40+
once: {
41+
handler() {
42+
console.log('Just once')
43+
}
44+
}
45+
}
46+
```
47+
2648
## Examples
2749

2850
```js
@@ -54,31 +76,6 @@ beforeDestroy() {
5476
}
5577
```
5678

57-
P.S.: Alternative way to set your event handlers is through the `on` and `once` Vue constructor options. In that way you shouldn't worry about removing event handlers on `beforeDestroy`.
58-
59-
```js
60-
/// Component 1
61-
62-
methods: {
63-
eventHandler(payload) {
64-
console.log('Yay, events work!', payload);
65-
},
66-
eventHandlerOnce(payload) {
67-
console.log('This will be called just once!');
68-
}
69-
},
70-
on: {
71-
test() {
72-
this.eventHandler();
73-
}
74-
},
75-
once: {
76-
test() {
77-
this.eventHandlerOnce();
78-
}
79-
}
80-
```
81-
8279
```js
8380
/// Component 2
8481

@@ -96,5 +93,21 @@ created() {
9693
}
9794
```
9895

96+
Alternative way to set your event handlers is through the `on` and `once` Vue constructor options. In that way you may not worry about removing event handlers in `beforeDestroy` hook. This approach makes code cleaner and reduces the amount of boilerplate code.
97+
98+
```js
99+
/// Component 1
100+
on: {
101+
test(payload) {
102+
console.log('Yay, events work!', payload);
103+
}
104+
},
105+
once: {
106+
test(payload) {
107+
console.log('This will be called just once!');
108+
}
109+
}
110+
```
111+
99112
## Demo
100-
[webpack 4 application](https://github.com/Raiondesu/webpack-vue-ts)
113+
[webpack 4 biolerplate](https://github.com/Raiondesu/webpack-vue-ts)

0 commit comments

Comments
 (0)