Skip to content

Commit c3b6706

Browse files
author
User
committed
added Options/Lifecycle APIs
1 parent 4bcec63 commit c3b6706

File tree

4 files changed

+199
-2
lines changed

4 files changed

+199
-2
lines changed

API.js

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ const G_C = require('./apis/globalconfig')
22
const G_API = require('./apis/globalapi')
33
const O_D = require('./apis/optionsdata')
44
const O_DOM = require('./apis/optionsdom')
5+
const O_LH = require('./apis/optionslifecyclehooks')
56

67
const GlobalConfig = [
78
G_C.SILENT,
@@ -45,10 +46,25 @@ const OptionsDOM = [
4546
O_DOM.RENDER_ERROR
4647
]
4748

49+
const OptionsLifecycleHooks = [
50+
O_LH.BEFORE_CREATE,
51+
O_LH.CREATED,
52+
O_LH.BEFORE_MOUNT,
53+
O_LH.MOUNTED,
54+
O_LH.BEFORE_UPDATE,
55+
O_LH.UPDATED,
56+
O_LH.ACTIVATED,
57+
O_LH.DEACTIVATED,
58+
O_LH.BEFORE_DESTROY,
59+
O_LH.DESTROYED
60+
61+
]
62+
4863

4964
module.exports = {
5065
GlobalConfig,
5166
GlobalAPI,
5267
OptionsData,
53-
OptionsDOM
68+
OptionsDOM,
69+
OptionsLifecycleHooks
5470
}

apis/optionsdom.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ const EL = {
2424
Runtime + Compiler build of Vue should be used.`
2525
,
2626
}
27-
// untested
27+
2828
const TEMPLATE = {
2929
category: 'Options/DOM',
3030
name: 'template',

apis/optionslifecyclehooks.js

Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
const chalk = require('chalk')
2+
const custom = require('../customcolors')
3+
const colorComment = custom.colorComment
4+
const colorPrimitive = custom.colorPrimitive
5+
const colorError = custom.colorError
6+
const colorArgs = custom.colorArgs
7+
8+
const cat = 'Options/Lifecycle Hooks'
9+
10+
const BEFORE_CREATE = {
11+
category: cat,
12+
name: 'beforeCreate',
13+
type: 'Function',
14+
details: `Called synchronously after the instance has just been initialized,
15+
before data observation and event/watcher setup.`
16+
}
17+
18+
const CREATED = {
19+
category: cat,
20+
name: 'created',
21+
type: 'Function',
22+
details: `Called synchronously after the instance is created.
23+
At this stage, the instance has finished processing the options
24+
which means the following have been set up: data observation, computed
25+
properties, methods, watch/event callbacks. However, the mounting phase
26+
has not been started, and the ${colorArgs('$el')} property will not be available yet.`
27+
}
28+
29+
const BEFORE_MOUNT = {
30+
category: cat,
31+
name: 'beforeMount',
32+
type: 'Function',
33+
details: `Called right before the mounting begins: the ${colorArgs('render')} function is
34+
about to be called for the first time.
35+
${chalk.bold('This hook is not called during server-side rendering')}.
36+
`
37+
}
38+
39+
const MOUNTED = {
40+
category: cat,
41+
name: 'mounted',
42+
type: 'Function',
43+
details: `Called after the instance has just been mounted where ${colorArgs('el')} is replaced by the newly created ${colorArgs('vm.$el')}.
44+
If the root instance is mounted to an in-document element, ${colorArgs('vm.$el')} will also be in-document
45+
when ${colorArgs('mounted')} is called. ${chalk.bold('This hook is not called during server-side rendering')}.
46+
47+
`
48+
}
49+
50+
const BEFORE_UPDATE = {
51+
category: cat,
52+
name: 'beforeUpdate',
53+
type: 'Function',
54+
details: `Called when the data changes, before the virtual DOM is re-rendered and patched.
55+
You can perform further state changes in this hook and they will not trigger additional re-renders.
56+
${chalk.bold('This hook is not called during server-side rendering')}.
57+
58+
`
59+
}
60+
61+
const UPDATED = {
62+
category: cat,
63+
name: 'updated',
64+
type: 'Function',
65+
details: `Called after a data change causes the virtual DOM to be re-rendered and patched.
66+
The component’s DOM will have been updated when this hook is called,
67+
so you can perform DOM-dependent operations here. However, in most cases
68+
you should avoid changing state inside the hook. To react to state changes,
69+
it’s usually better to use a ${chalk.green('computed property')} or ${chalk.green('watcher')} instead.
70+
${chalk.bold('This hook is not called during server-side rendering')}.
71+
`
72+
}
73+
74+
const ACTIVATED = {
75+
category: cat,
76+
name: 'activated',
77+
type: 'Function',
78+
details: `Called when a kept-alive component is activated.
79+
${chalk.bold('This hook is not called during server-side rendering')}.`
80+
}
81+
82+
const DEACTIVATED = {
83+
category: cat,
84+
name: 'deactivated',
85+
type: 'Function',
86+
details: `Called when a kept-alive component is deactivated.
87+
${chalk.bold('This hook is not called during server-side rendering')}.`
88+
}
89+
90+
const BEFORE_DESTROY = {
91+
category: cat,
92+
name: 'beforeDestroy',
93+
type: 'Function',
94+
details: `Called right before a Vue instance is destroyed. At this stage the instance is
95+
still fully functional. ${chalk.bold('This hook is not called during server-side rendering')}.`
96+
}
97+
98+
const DESTROYED = {
99+
category: cat,
100+
name: 'destroyed',
101+
type: 'Function',
102+
details: `Called after a Vue instance has been destroyed. When this hook is called, all directives of the Vue instance
103+
have been unbound, all event listeners have been removed, and all child Vue instances have also been
104+
destroyed. ${chalk.bold('This hook is not called during server-side rendering')}.`
105+
}
106+
107+
module.exports = {
108+
BEFORE_CREATE,
109+
CREATED,
110+
BEFORE_MOUNT,
111+
MOUNTED,
112+
BEFORE_UPDATE,
113+
UPDATED,
114+
ACTIVATED,
115+
DEACTIVATED,
116+
BEFORE_DESTROY,
117+
DESTROYED
118+
}

vue-help.js

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ const gc = api.GlobalConfig
77
const ga = api.GlobalAPI
88
const od = api.OptionsData
99
const odom = api.OptionsDOM
10+
const olh = api.OptionsLifecycleHooks
1011

1112
V.delimiter('vue-help$').show()
1213

@@ -196,4 +197,66 @@ V.command('renderError', 'Options/DOM: #renderError').action(function(args, call
196197
const w = odom[3]
197198
this.log(O.logOptions(w))
198199
callback()
200+
})
201+
202+
// Options/Lifecycle Hooks
203+
204+
V.command('beforeCreate', 'Options/Lifecycle Hooks: #beforeCreate').action(function(args, callback){
205+
const w = olh[0]
206+
this.log(O.logOptions(w))
207+
callback()
208+
})
209+
210+
V.command('created', 'Options/Lifecycle Hooks: #created').action(function(args, callback){
211+
const w = olh[1]
212+
this.log(O.logOptions(w))
213+
callback()
214+
})
215+
216+
V.command('beforeMount', 'Options/Lifecycle Hooks: #beforeMount').action(function(args, callback){
217+
const w = olh[2]
218+
this.log(O.logOptions(w))
219+
callback()
220+
})
221+
222+
V.command('mounted', 'Options/Lifecycle Hooks: #mounted').action(function(args, callback){
223+
const w = olh[3]
224+
this.log(O.logOptions(w))
225+
callback()
226+
})
227+
228+
V.command('beforeUpdate', 'Options/Lifecycle Hooks: #beforeUpdate').action(function(args, callback){
229+
const w = olh[4]
230+
this.log(O.logOptions(w))
231+
callback()
232+
})
233+
234+
V.command('updated', 'Options/Lifecycle Hooks: #updated').action(function(args, callback){
235+
const w = olh[5]
236+
this.log(O.logOptions(w))
237+
callback()
238+
})
239+
240+
V.command('activated', 'Options/Lifecycle Hooks: #activated').action(function(args, callback){
241+
const w = olh[6]
242+
this.log(O.logOptions(w))
243+
callback()
244+
})
245+
246+
V.command('deactivated', 'Options/Lifecycle Hooks: #deactivated').action(function(args, callback){
247+
const w = olh[7]
248+
this.log(O.logOptions(w))
249+
callback()
250+
})
251+
252+
V.command('beforeDestroy', 'Options/Lifecycle Hooks: #beforeDestroy').action(function(args, callback){
253+
const w = olh[8]
254+
this.log(O.logOptions(w))
255+
callback()
256+
})
257+
258+
V.command('destroyed', 'Options/Lifecycle Hooks: #destroyed').action(function(args, callback){
259+
const w = olh[9]
260+
this.log(O.logOptions(w))
261+
callback()
199262
})

0 commit comments

Comments
 (0)