-
-
Notifications
You must be signed in to change notification settings - Fork 924
This issue was moved to a discussion.
You can continue the conversation there. Go to discussion →
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
Official component/utility library #2284
Comments
@orbitbot How broadly useful is that? I'd rather keep our bar high here, and |
It wasn't a strong suggestion, mainly one of convenience in that it's easy to provide default options and add code that is run every time a request is made. |
I would love to see some component / util library in place for mithril. Even if some approaches might be opinionated, i think it will help every new comer to wrap the head around some basic concepts and its pro/cons. Me personally, i had to implement a multilingual page. This sound easy, but the translations needed to be available for server side rendering and i made some big mistakes while implementing it and some pages got rendered in the wrong language... i would love to share my approach within a common mithril library. |
@ChrisGitIt This component library wouldn't include any UI components, at least initially. It'd start out purely control- and API-related. As for I18n, Mithril is itself massive overkill. You'll have better success using a library (like any of these) or a quick hack, and each of these will work flawlessly on server-side, too. Plus, In case you're curious how simple that above function i18n(label) { return i18n.db[i18n.locale || "en"][label] }
i18n.locale = "en"
i18n.db = {}
// Set the current locale using this:
i18n.locale = "es"
// Add keys like this:
i18n.db["en"] = {hello: "Hello!", bye: "Goodbye!", ...}
i18n.db["es"] = {hello: "¡Holá!", bye: "¡Adiós!", ...}
i18n.db["jp"] = {hello: "お早う!", bye: "左様なら!", ...} Of course, it's very simple and it doesn't support things like pluralization, but you get the point. |
Hi @isiahmeadows, and thanks for your infos. I actually thought more about the "dynamic" problems that do arise while working with translations (mostly SSR concerns) and SPAs. So here are some "problems" that will arise if not properly approached (like i did): 2: Using a dynamic loading approach might be easily possible on the client, but if you are on the server (SSR), the translations need to be encapsulated AND the encapsulated translations needed to be passed to every component that needs it (otherwise, it might happen server side that "en" is loading, but "de" is loaded quicker and then the translation is a different one... was this understandable? Took me some time to see my implementation flaw ... 3: ... some more problems that i do not (want) to remember ;-) So i think it would be nice to have component/util library that is not only a pure "plug&play" but also shows some drawbacks and possible solutions to integrate with mithril (like using the "onmatch" route component). |
Just to chim in my support, I'd very much love to have a |
This issue was moved to a discussion.
You can continue the conversation there. Go to discussion →
Updates
Now that we're starting to see several common themes, I don't think it'd be a terrible idea to start having an official userland component/utility library for the common requests and things otherwise broadly useful. For example:
Async
: See Add a built-in component for async view loading #2282. It simplifies async view loading to something that's a lot easier to use.Route
: The router itself might qualify for inclusion here if we go for Make the router use components, but only accept view functions #2281.m.buildQueryString
andm.parseQueryString
should be transferred with this - they're not broadly useful outside routing.Link
: For the common case ofm("a", {oncreate: m.route.link(opts = {})})
, a lot of people (me included) would like to see an easier way of specifying links than this verbosity. This one is probably the only one that really merits core inclusion, though.SelfSufficient
: We've decided that it belongs in userland, but there's been so many requests for this both here and on Gitter for subtree management that I feel it needs a more centralized home.stream
: Mithril's streams library really belongs here, not necessarily at the top level.Request
: Mithril's request library,m.request
/m.jsonp
, could fit here, if we want to keep most of the batteries out of core.fetch
, so I'm not sure this is as broadly useful in core as it used to be. If you're stuck on IE, you of course would still appreciate this.hydrate
: We've decided it's probably not ideal to include in core, but it'd definitely be worth having at least supported in some official capacity.Each of these would be distinct utilities out of core, not shipped with the main bundle. This would almost function like Mithril's "standard library", basically anything that doesn't belong in Mithril itself, but is still useful nevertheless.
My thought is adopting
mithril/util/${module}
for each of these, wheremithril/util
re-exports everything.Of course we currently do have such a subfolder, but we could rename that toEdit: removed as of #2317.core-util
, things we ship with the main bundle, to make room for this new namespace.The text was updated successfully, but these errors were encountered: