Skip to content

How Do I Port Mithril 0.x to 1.x

Manabu Tokunaga edited this page Mar 18, 2017 · 2 revisions

Problem

You have a code-base written for Mithril 0.x. Now you want to port that to Mithril 1.x.

Solution

Read The Migration Document on the Mithril Web Site.

There is a lot of information covered in the Migration Page. Also read Mithril Migration Path.

Run the Codemods Migration Utility

You can at least automate about half of the migration issue with Mithril Codemods. You will still need to deal with the rest by hand.

Some Key Gotchas

  • Controllers will have to be reworked, this needs your understanding of the Lifecycle Methods concept. Especially important is the state that goes with vnode. That's where you hook up your controller/service code.

  • In Typescript Component and Vnode are parametrized with <State, Attrib> therefore, your Controller class can go in there or it can be a member of another class that defines the State class. Attrib's main purpose is to serve as a data structure class that will be passed to a component when you are instantiating it. If you do not have an appropriate class for either of those, supply <any, any> or <{}, {}>.

  • prop is now renamed to stream() and it is also a different "module", in the system although functionally equivalent.

If you alias stream back into prop like;

import prop = stream;

You probably do not need to alter a lot of your Typescript code.