Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

m.mount no return value #2068

Closed
yulei745 opened this issue Jan 9, 2018 · 6 comments
Closed

m.mount no return value #2068

yulei745 opened this issue Jan 9, 2018 · 6 comments
Labels
Type: Question For issues that are purely questions about Mithril, not necessarily bug reports or suggestions

Comments

@yulei745
Copy link

yulei745 commented Jan 9, 2018

0.2.x version m.mount return value, 1.x m.mount no return value, how to do upgrade

@dead-claudia dead-claudia added the Type: Question For issues that are purely questions about Mithril, not necessarily bug reports or suggestions label Jan 9, 2018
@dead-claudia
Copy link
Member

@yulei745 Could you give more info on your specific case?

Note: m.mount accepts a component, and the lifecycle does this, so you may be able to adapt accordingly:

  • Call m.mount with component:
    • If an existing tree is mounted, call m.mount(elem, null)
    • Else, clear any existing children
    • Invoke component oninit
    • Invoke component view
    • Call m.render with its result
    • Invoke component oncreate
    • Return
  • Call m.redraw() (or on implicit redraws):
    • Invoke component onbeforeupdate
    • Invoke component view
    • Call m.render with its result
    • Invoke component onupdate
    • Return
  • Call m.mount(elem, null):
    • Invoke component onbeforeremove if it exists
    • If necessary and if its result is a thenable, await its result, return, and execute the next steps in the then callback
    • Call m.render with no children
    • Invoke component onremove
    • If we didn't need to await, return

@yulei745
Copy link
Author

yulei745 commented Jan 10, 2018

@isiahmeadows
look case

<div id="modal"></div>
<script type="text/javascript">
class ModalManager {
    oninit(vnode) {
         this.component = null;
     }
    oncreate(vnode) {
        this.dom = vnode.dom;
    }

    view(vnode) {
        return (
            <div className="ModalManager modal fade">
                 m(this.component);
            </div>
            );
    }

    show(component) {
       //use bootstrap modal
        this.component = component;
        $(this.dom).modal({'show': true});
    }
}

class loginmodal {
  view() {
     return '<div>loginmodal</div>';
  }
}

var modal = m.mount(document.getElementById('modal'), ModalManager);


modal.show(loginmodal);
</script>

@dead-claudia
Copy link
Member

Try something like this:

let state

m.mount(document.getElementById("modal"), {
    view() { return m(ModalManager, {oninit(vnode) { state = vnode.state }}) },
})

The lifecycle methods are also available as attributes, and although it's not documented (even though it should be), vnode.state points to your component's state.

@yulei745
Copy link
Author

In other words, less state machine management, if there are many components, the state is not very managed.

@dead-claudia
Copy link
Member

@yulei745 If you're needing something that scales, your app will need a lot of refactoring. Also, note that v1 is a breaking upgrade, and accordingly, we've compiled a migration guide to help you out, if you haven't read it already.

@yulei745
Copy link
Author

Thank you, I probably know how to get it

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Type: Question For issues that are purely questions about Mithril, not necessarily bug reports or suggestions
Projects
None yet
Development

No branches or pull requests

3 participants