These are chat archives for mithriljs/mithril.js

9th
Apr 2016
khades
@khades
Apr 09 2016 04:33
ye, after somebody talking not liking domain-oriented frameworks
i have no idea what should i use for a rest framework on js
_bran
@BransonGitomeh
Apr 09 2016 05:45
@drew111b those settings for cors are mostly on the server
in my position the browser usually sends and OPTIONS request before any POST to check if cors is supported if that one fails, the entire thing fails
Metin Akat
@loxs
Apr 09 2016 08:30
is there any other way (aside of configuring a global variable) to pass config options to my components? Is this documented somewhere?
khades
@khades
Apr 09 2016 08:30
pass them as args
second parameter to a m.component()
Metin Akat
@loxs
Apr 09 2016 08:31
but how (sorry , still a newbie)
khades
@khades
Apr 09 2016 08:31
m.component(MyAwesomeComponent, args)
and then in components controller/view you can get them
Constantin Angheloiu
@cmnstmntmn
Apr 09 2016 08:31
you could wrap them in a module
khades
@khades
Apr 09 2016 08:31
since view is function(ctrl, args) and controller is function(args)
Constantin Angheloiu
@cmnstmntmn
Apr 09 2016 08:32
and require in your other modules (components)
Metin Akat
@loxs
Apr 09 2016 08:32
I don't require anything yet... still working in a single file and trying to make sense of it :)
khades
@khades
Apr 09 2016 08:32
pass them as arguments
Metin Akat
@loxs
Apr 09 2016 08:32
yeah, thanks
this is what you want
Metin Akat
@loxs
Apr 09 2016 08:34
yes, found it after you told me, thanks
khades
@khades
Apr 09 2016 08:34
np
Constantin Angheloiu
@cmnstmntmn
Apr 09 2016 08:34
cons person = {title: 'name', age:13} then make use of dot selector
const
khades
@khades
Apr 09 2016 08:35
object is object
Metin Akat
@loxs
Apr 09 2016 08:50
what is the proper way to do a blocking request?
khades
@khades
Apr 09 2016 08:55
blocking?
why do you want a blocking request?
you can chain requests
i mean chain promises
Metin Akat
@loxs
Apr 09 2016 08:57
well, it's the initial request where I check the validity of my token agains the server
I don't want my app to do anything else before that is done
khades
@khades
Apr 09 2016 08:57
so?
do request and do anything else in .then()
Metin Akat
@loxs
Apr 09 2016 08:57
so basically my whole app goes in the .then?
khades
@khades
Apr 09 2016 08:57
check the validity of my token agains the server
do it on every request intead
everyone does that
i mean send requests with tokens
Metin Akat
@loxs
Apr 09 2016 08:58
yeah, but on page load I want to display login form
if token no more valid
of course I also send tokens on all requests
khades
@khades
Apr 09 2016 08:58
construct other m.request with custom logic
and use it everywhere
i mean wrap the m.request in such manner it would do what you want
Metin Akat
@loxs
Apr 09 2016 08:59
right...
thanks
khades
@khades
Apr 09 2016 08:59
all my requests have oauth token in it
and everyone who uses oauth tokens just send them with every request
Evgeniy Labutin
@LabEG
Apr 09 2016 09:05
@isiahmeadows ping, you use typings with js?
Dominic Gannaway
@trueadm
Apr 09 2016 10:30
@lhorie saw you mentioned that you've got awesome dbmonster perf now :) great work
in terms of the React parity, that was a decision made for inferno-component which isn't in core
people don't have to use ES2015 classes at all in Inferno to use components, in fact, stateless components are my preferred method
khades
@khades
Apr 09 2016 10:32
cached state is a go for me
Dominic Gannaway
@trueadm
Apr 09 2016 10:32
along with Inferno's hooks so you can give stateless components lifecycle events to further optimize performance. I expect this is one area that React will copy Inferno
Metin Akat
@loxs
Apr 09 2016 12:44
is there an example of "login workflow"? I mean, routing with a "login" page that navigates back to the page of interest after successful login
khades
@khades
Apr 09 2016 12:47
i got wrapped request
when i populate page with request
m.request({
  method: "GET",
  url: "/api/channelData/add"
}).then(function(info) {
  this.eventTypes = info.eventTypes;
  this.username = m.prop(info.username)
}.bind(this), function(error) {
  if (error.status == 401) {
    localStorage.setItem("redirect", m.route());
    window.location = "/oauth/initiateAuth"
  }
widnow location cause of oauth, you can use m.route as well properly
so after auth i pull "redirect" from localStorage and redirect to it
Metin Akat
@loxs
Apr 09 2016 12:49
I see
in my case it's supposed to be "easier" as my backend is the login privder
but i can do it this way as well of course
Metin Akat
@loxs
Apr 09 2016 17:20
This message was deleted
This message was deleted
This message was deleted
This message was deleted
Metin Akat
@loxs
Apr 09 2016 17:25
ah, sorry, found it
Metin Akat
@loxs
Apr 09 2016 19:45
m("a[href='/dashboard/alicesmith']", {config: m.route});
is there any good reason for this not to support just the href property of the object?
Arthur Clemens
@ArthurClemens
Apr 09 2016 19:46
what do you mean?
Metin Akat
@loxs
Apr 09 2016 19:46
it's a PITA to generate these a[href='/dashboard/alicesmith']
Arthur Clemens
@ArthurClemens
Apr 09 2016 19:47
the href property of the object
which object?
Metin Akat
@loxs
Apr 09 2016 19:48
sorry
I didn't say what I'm talking about
end of page
"Mode abstraction"
and I don't like the idea at all :)
so it seems I have to generate these strings of the kind "a[href='/dashboard/alicesmith']"
Arthur Clemens
@ArthurClemens
Apr 09 2016 19:49
you can either write "a[href=‘...’]" or
a”, {
    href:”…”,
    config: m.route
}
Metin Akat
@loxs
Apr 09 2016 19:50
yeah, but isn't the next sentence in the docs say "do not use this"?
Arthur Clemens
@ArthurClemens
Apr 09 2016 19:50
where the href is the route path
it just says to use the ideomatic route path
and not the resulting url
Metin Akat
@loxs
Apr 09 2016 19:51
hmm, so this should work then, what you pasted
I need to report a bug probably
Arthur Clemens
@ArthurClemens
Apr 09 2016 19:51
sure, I use it all the time
Metin Akat
@loxs
Apr 09 2016 19:51
still haven't figured out exactly what is wrong and why
Arthur Clemens
@ArthurClemens
Apr 09 2016 19:51
It's a good practice to always use the idiom above, instead of hardcoding ? or # in the href attribute.
where “idiom” refers to the route
Metin Akat
@loxs
Apr 09 2016 19:52
but it doesn't work with route mode "pathname"
Arthur Clemens
@ArthurClemens
Apr 09 2016 19:52
not to the href attribute
Metin Akat
@loxs
Apr 09 2016 19:52
it works with hash
Arthur Clemens
@ArthurClemens
Apr 09 2016 19:52
you need to set up the server for pathname
Metin Akat
@loxs
Apr 09 2016 19:52
I know and I have done it
Arthur Clemens
@ArthurClemens
Apr 09 2016 19:52
hash and query work out of the box
Metin Akat
@loxs
Apr 09 2016 19:53
it always serves the same page on everything under /admin
but mithril routes break when I don't start from /admin, but instead start from /admin/something
Arthur Clemens
@ArthurClemens
Apr 09 2016 19:53
what is your route object?
Metin Akat
@loxs
Apr 09 2016 19:54
I'm not sure how to paste nicely
sorry if it doesn't work :)
but I'll try
    var url = function(path){
        return Config.rooturl + path;
    };
    m.route.mode = "pathname";
    //m.route.mode = "hash";
    var routes = {};
    routes[url("")] = Page;
    routes[url("/")] = Page;
    routes[url("/login")] = Page;
    routes[url("/players")] = Page;
    routes[url("/clubs")] = Page;
    m.route(document.body, url(""), routes);
Arthur Clemens
@ArthurClemens
Apr 09 2016 19:55
where is /admin/something?
Metin Akat
@loxs
Apr 09 2016 19:55
it is for example /admin/login
which is the routes[url("/login")] = Page;
my url() function prepends /admin in front of everything
Arthur Clemens
@ArthurClemens
Apr 09 2016 19:57
I assume that Config.rooturl does not change
Metin Akat
@loxs
Apr 09 2016 19:57
it does not
it can change if I deploy the app to a different url, though it doesn't change over the lifetime of a browser session
Arthur Clemens
@ArthurClemens
Apr 09 2016 19:59
and Page is the wrapper component I assume. Can you check there if the route does change?
Metin Akat
@loxs
Apr 09 2016 20:00
it is the wrapper component. I'm not sure what you asked me to check
Arthur Clemens
@ArthurClemens
Apr 09 2016 20:01

it always serves the same page on everything under /admin

does the route actually change?

Metin Akat
@loxs
Apr 09 2016 20:01
it does
Arthur Clemens
@ArthurClemens
Apr 09 2016 20:02
then I don’t understand why it works with hash and not with pathname
Metin Akat
@loxs
Apr 09 2016 20:03
I don't too
I'm trying to figure it out and I'll report
here is my menu component
var Menu = {
view: function(){
    console.log(m.route());
    var sections = Config.menu.map(function(section, index){
        var menuItems = section.links.map(function(item){
            //console.log(item);
            var menuItemClass = item.url == m.route() ?
                "menu-item-active" : "menu-item";
            return m("div", {class: menuItemClass},
                     [m("a",
                        {href: item.url, config: m.route},    item.name)]);
        });
        return m("div", {class: "menu-section"},
                 [m("div", {class: "menu-section-name"},
                    section.section_name)].concat(menuItems)
                );
    });
    return m("div", {class: "menu"}, sections);
}
};
which drives the whole thing
so the problem is
everything works
the url in the address bar changes when I click on menu items etc.
the console.log in the view prints the correct url
but nothing works
clicking on menu items causes the dom to redraw, but the url in the address bar does not change
Arthur Clemens
@ArthurClemens
Apr 09 2016 20:08
and item.url is equal to the route path?
Metin Akat
@loxs
Apr 09 2016 20:08
yes, item.url is something like "/admin/login"
and if I change the route mode to "hash", everything works, no matter where I start from
and it generates urls of the kind
http://localhost:8001/admin#/admin/players (because I didn't remove my url() function which prepends "/admin")
if I reload at the above url, all works fine
Metin Akat
@loxs
Apr 09 2016 20:19
I think somehow the prefix bugs it... the one I add to all of my urls
Arthur Clemens
@ArthurClemens
Apr 09 2016 20:23
someone mentioned on github that he needed to add a base href to the html head
Metin Akat
@loxs
Apr 09 2016 20:25
it's not the end of the world, I'll use hash mode
let's hope I don't have scrolling problems
should I report this as a bug?
regretfully, I can't provide any better info
Arthur Clemens
@ArthurClemens
Apr 09 2016 22:35
Mithril 2.0.3 is giving me quite some headaches because of the difference in component handling. It is now almost always required to use key. When this happens in a not-so-small app it is really hard to figure out that is the cause.
khades
@khades
Apr 09 2016 22:35
living so far in future almost guarantees you a headache
Arthur Clemens
@ArthurClemens
Apr 09 2016 22:36
I’ve said myself that I was expecting breaking changes...