Skip to content
This repository has been archived by the owner on Nov 30, 2020. It is now read-only.

implement event based registration as mixin #113

Open
matsp opened this issue May 25, 2018 · 2 comments
Open

implement event based registration as mixin #113

matsp opened this issue May 25, 2018 · 2 comments
Assignees

Comments

@matsp
Copy link
Owner

matsp commented May 25, 2018

Avoid direct child access via $children.

Parent components should only listen for specific IDs.

e.g.

  • FormField <-> Checkbox
@matsp matsp self-assigned this May 25, 2018
@tychenjiajun
Copy link
Contributor

I'm planning on adding a function emit in baseComponentMixin like the following

function emit (target: Element, eventType: string, payload) { /* ... */ }

and change the mounted hook in every component

<div @initialized="onInit"></div> <!-- some material component here -->
mounted () {
    this.mdcComponent = MDCComponent.attachTo(this.$el) // initialize itself and may cause some DOM and style change
    this.$nextTick(() => { // use nextTick because we have to wait for the DOM change  
        this.emit(this.mdcComponent.someChild_.root_, 'initialized', this.mdcComponent.someChild_) // useful for components that initialize their children like drawer, text-field and tab bar
        this.emit(this.$slots.default.$el, 'form-initialized', this.mdcFormField) // useful for form field
    })
},
methods: {
    onInit (component) {
         this.mdcComponent = component 
    },
    onFormInit (formFieldComponent) { /* ... */ }
}

@tychenjiajun
Copy link
Contributor

Use provide/inject together with event is also a solution

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants