Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 9bf3f6e

Browse filesBrowse files
committed
change EventName and remove events in vue.Option
1 parent da3448e commit 9bf3f6e
Copy full SHA for 9bf3f6e

File tree

Expand file treeCollapse file tree

2 files changed

+17
-33
lines changed
Filter options
Expand file treeCollapse file tree

2 files changed

+17
-33
lines changed

‎component.go

Copy file name to clipboardExpand all lines: component.go
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ func NewComponent(
7272
opt.Data = vmfn
7373
opt.Template = templateStr
7474
opt.Replace = replace
75-
opt.OnLifeCycleEvent(VmInit, func(vm *ViewModel) {
75+
opt.OnLifeCycleEvent(EvtBeforeCreate, func(vm *ViewModel) {
7676
vm.Options.Set("methods", js.MakeWrapper(vmfn()))
7777
vMap[vmfn()] = vm
7878
})

‎option.go

Copy file name to clipboardExpand all lines: option.go
+16-32Lines changed: 16 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -10,19 +10,19 @@ import (
1010
type LifeCycleEvent string
1111

1212
const (
13-
VmInit LifeCycleEvent = "init"
14-
VmCreated LifeCycleEvent = "created"
15-
VmBeforeCompile LifeCycleEvent = "beforeCompile"
16-
VmCompiled LifeCycleEvent = "compiled"
17-
VmReady LifeCycleEvent = "ready"
18-
VmAttached LifeCycleEvent = "attached"
19-
VmDetached LifeCycleEvent = "detached"
20-
VmBeforeDestroy LifeCycleEvent = "beforeDestroy"
21-
VmDestroyed LifeCycleEvent = "destroyed"
13+
EvtBeforeCreate LifeCycleEvent = "beforeCreate"
14+
EvtCreated LifeCycleEvent = "created"
15+
EvtBeforeMount LifeCycleEvent = "beforeMount"
16+
EvtMounted LifeCycleEvent = "mounted"
17+
EvtBeforeUpdate LifeCycleEvent = "beforeUpdate"
18+
EvtUpdated LifeCycleEvent = "updated"
19+
EvtActivated LifeCycleEvent = "activated"
20+
EvtDeactivated LifeCycleEvent = "deactivated"
21+
EvtBeforeDestroy LifeCycleEvent = "beforeDestroy"
22+
EvtDestroyed LifeCycleEvent = "destroyed"
2223
)
2324

24-
// Option are used to organize mutiple sub component together to
25-
// construct VueJS apps or (higher level) components.
25+
// Option is used to config VueJS instance or to create VueJS components.
2626
type Option struct {
2727
*js.Object
2828

@@ -139,9 +139,7 @@ type Option struct {
139139
Parent *js.Object `js:"parent"`
140140

141141
// map to sub component
142-
mcom map[string]*Component
143-
// map to event handler
144-
mevt map[string]interface{}
142+
coms map[string]*Component
145143
// properties
146144
props []string
147145
// mixins
@@ -152,8 +150,7 @@ func NewOption() *Option {
152150
c := &Option{
153151
Object: js.Global.Get("Object").New(),
154152
}
155-
c.mcom = make(map[string]*Component, 0)
156-
c.mevt = make(map[string]interface{}, 0)
153+
c.coms = make(map[string]*Component, 0)
157154
c.props = []string{}
158155
c.mixins = []js.M{}
159156
return c
@@ -174,11 +171,8 @@ func (o *Option) NewComponent() *Component {
174171

175172
// prepare set the proper options into js.Object
176173
func (c *Option) prepare() (opts *js.Object) {
177-
if len(c.mcom) > 0 {
178-
c.Set("components", c.mcom)
179-
}
180-
if len(c.mevt) > 0 {
181-
c.Set("events", c.mevt)
174+
if len(c.coms) > 0 {
175+
c.Set("components", c.coms)
182176
}
183177
if len(c.props) > 0 {
184178
c.Set("props", c.props)
@@ -243,17 +237,7 @@ func (c *Option) addMixin(name string, val interface{}) *Option {
243237

244238
// AddComponent add sub component to the genereated VueJS instance (optional)
245239
func (c *Option) AddSubComponent(name string, sub *Component) *Option {
246-
c.mcom[name] = sub
247-
return c
248-
}
249-
250-
// On add EventHandler to VueJS-generated component-oriented event
251-
// for cross component message passing
252-
func (c *Option) On(event string, fn func(vm *ViewModel, args []*js.Object)) *Option {
253-
c.mevt[event] = js.MakeFunc(func(this *js.Object, args []*js.Object) interface{} {
254-
fn(newViewModel(this), args)
255-
return nil
256-
})
240+
c.coms[name] = sub
257241
return c
258242
}
259243

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.