These are chat archives for mithriljs/mithril.js

30th
Sep 2015
mrtracy
@mrtracy
Sep 30 2015 02:35
alright, i'm back. I've modified your example so that it uses concrete types, and it no longer compiles
mrtracy
@mrtracy
Sep 30 2015 02:41
If all of the different subtypes can be converted to a single type through duck typing, it will work - however, this only works because the different types are actually the same type
mrtracy
@mrtracy
Sep 30 2015 02:48
well, actually is a bit more complicated than that, apparently an instance of Class A can be "duck typed" as Class B if its interface is a superset of Class A
so, let me modify your first example to fail: http://bit.ly/1PMz2nL
what I did was:
  1. Remove "foo" from the function call, leaving only "bar" and "baz". Since "foo" is not a candidate, only the types of "bar" or "baz" can be considered, and neither is a superset of the other
  2. Convert func() to take the parameters as a variadic set (...args: T[]). Apparently, if you pass it directly as an array it can work, and they type is (Bar | Baz)[] - I believe this is because of Typescript's support for "Tuple Types"
mrtracy
@mrtracy
Sep 30 2015 02:55
anyways, in the case of MithrilRoutes<T extends MithrilController>, if one of the component's controllers is trivial and has no methods, all of the other controllers will be considered as a member of that trivial type. However, if all of the component controllers are non-trivial and none is a subset of all of the others, then MithrilRoutes will not compile because of this error
I actually learned quite a bit more about the type inference in TypeScript trying to work out what was going wrong here
Isiah Meadows
@isiahmeadows
Sep 30 2015 05:51
@mrtracy That's because T resolves to Bar | Baz. It doesn't resolve to Foo, the super type. If you explicitly annotate the type, it doesn't fail. That's a TypeScript fail, not Mithril.
Isiah Meadows
@isiahmeadows
Sep 30 2015 05:58
TypeScript can't infer everything. Even Haskell has its limitations, and that has one of the most powerful type systems of all languages.
Rodrigo Álvarez
@Papipo
Sep 30 2015 07:39
would you do something like this? http://stackoverflow.com/a/9425116/396090
I want something like that in my ViewModel
in order to attach/detach listeners to elements for example
Rodrigo Álvarez
@Papipo
Sep 30 2015 07:48
What I am doing feels kinda wrong. I need to run some code when args passed to my view change. Maybe I can approach this differently
Rodrigo Álvarez
@Papipo
Sep 30 2015 08:02
Rodrigo Álvarez
@Papipo
Sep 30 2015 09:22
Not sure if this is orthodox, but I have added a scope.vm.refresh() method at the top of my view function
that, plus some "observable" props, allow me to do stuff when the component arguments change
Feedback is welcome
Rodrigo Álvarez
@Papipo
Sep 30 2015 15:14
when a third party lib modifies the DOM, for example adding a className to an element, is there a way to retain that, or should I just add a listener to add the class myself back? The problem with the latter approach is that the integration is coupled, and if the class changes or something, it will stop working
Sorry for the SPAM :D
Stephan Hoyer
@StephanHoyer
Sep 30 2015 18:23
Can you give an example?
Rodrigo Álvarez
@Papipo
Sep 30 2015 19:19
calling showTab() will add an .active class to the tab, besides firing a "show" event
The easiest solution is to store the fact that the tab is shown and add the .active class on the mithril view
but that seems hacky
Rodrigo Álvarez
@Papipo
Sep 30 2015 22:36
anyway, I've been the last three days fighting mithril. It seems that I just needed to use the config attr