Git Product home page Git Product logo

Comments (5)

ciscoheat avatar ciscoheat commented on August 23, 2024

I think it's the expected behavior, since you're bypassing Mithril's controller handling when creating the Test objects yourself and assigning them in a normal Haxe class. If you use routes, you may get a different result since all controllers are called again when the route changes.

The more I use mithril-hx, the less I'm relying on the controller method, since it works as a constructor in Mithril, which we already have with Haxe's classes.

from mithril-hx.

benmerckx avatar benmerckx commented on August 23, 2024

Using the router works as expected, but in this case it's not a good fit. I'm using it for developing a cordova app, where I have no use for routing really. I mainly use the controller method in cases where I need some stuff done when the components mounts/unmounts (for example adding/removing an event listener to the window object). The combination of controller/unonload is really useful for that. I could replace it by using config on the root element of the view (with ctx.onunload), but that means I'm relying on the component to be rendered first. So I'm unsure what the right way to do this would be.

from mithril-hx.

ciscoheat avatar ciscoheat commented on August 23, 2024

Ok, I see! Looking at https://lhorie.github.io/mithril/mithril.component.html#unloading-components it seems that you have to call mount again to make your case work, instead of using redraw (which is only view-related). Does it work to replace the M.redraw calls in your example with the same M.mount call?

from mithril-hx.

benmerckx avatar benmerckx commented on August 23, 2024

Thanks, I see. I've misinterpreted the use of the controller method. I've solved this for my case by calling a mount/unmount method on the components since they all pass through the same method. Something like this:

public function setView(view) {
  if (component != null) component.unmount();
  component = view;
  component.mount();
}

Thanks for the help and your work on the externs!

from mithril-hx.

ciscoheat avatar ciscoheat commented on August 23, 2024

Glad to help. :)

from mithril-hx.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.