Comments (15)
@StephanHoyer nice :)
I'm actually working on something similar too. A few things to consider: empty elements (e.g. <br />
), and maybe considering handling events based on the value type instead of their names
from mithril.js.
i made this one in 35 lines if anyone is interested
https://gist.github.com/ancmikesmullin/102bcba5836362d46f4c0e7880e5a98f
from mithril.js.
Yeah, there's a couple of ways to do it.
One way is to implement a function that takes virtual elements and spits out an HTML string. A virtual element is a object that looks like
{tag: "div", attrs: {id: "foo", class: "bar"}, children: [ "a text node", /*other virtual elements */ ]}
You'd call this method instead of m.render if you're piecing things together manually.
I have a snippet that does this somewhere in my hard drive, but I haven't published it w/ the project. I'll go dig it up, but in the meantime, if you're feeling up to writing a bit of code, it's just a recursive function and not that hard to re-implement.
There's also an undocumented way, which is to mock the window
dependency with the m.deps
method. I have an example of this in the tests folder (mock.js), and a mock implementation that you can adapt to produce html strings as a side effect.
This second method is probably the more useful one, since it allows you to run the entire app on a programmable "browser"-in-the-server without the need for PhantomJS or similar.
I'm planning on releasing both the virtual-dom-to-html-string utlility method and a proper node.js adapter when I get the chance.
from mithril.js.
you can use min-document or html-element as minimal DOM implementations.
Both of those support serializing their DOM representations to a HTML string.
You can also write a stringifier for a vdom representation by finding another stringifier and adjusting it to support mithril vdom like stringify.
from mithril.js.
Did you ever release that dom-to-string utility?
from mithril.js.
https://github.com/alexmingoia/virtual-dom-stringify
from mithril.js.
Cheers Raynos!
from mithril.js.
https://github.com/StephanHoyer/mithril-node-render
from mithril.js.
good point!
Fixed this
from mithril.js.
@lhorie, @StephanHoyer, @Raynos
Hello, everyone. Can you tell what's the status on this? Which soultion is preferred now?
@yanns, are you using some particular solution and if yes, which one?
from mithril.js.
@StreetStrider I'd use @StephanHoyer's library
from mithril.js.
@StreetStrider we've been using @StephanHoyer's library for months, it's exactly what you'd want.
from mithril.js.
@lhorie @tivac, Thanks for help! I'll certainly investigate it.
Also, thanks for keeping mithril in way of modularity and composability.
from mithril.js.
Hello persons. I've been trying out @StephanHoyer 's mithril-node-render. There's this issue with parameters to routes mentioned in his article (about his package). In order to get a parameter in your controller you have to do something like var stuff = params ? params.stuff : m.route.param('stuff')
.
Quoting:
This can be improved of cause. I simply did not come up with an elegant solution for this. Any ideas?
So, did anyone did come up with an elegant solution?
from mithril.js.
For what it's worth, for this reason alone I'm considering resurrecting my m-iso. Mithril itself simply relies too much on the DOM to sufficiently be useful in isomorphic applications. That's how it can stay so small. You'd be effectively reimplementing Mithril along with half of the DOM if you were to try to shim it into working in Node, especially if you're doing more than just rendering simple views and controllers (no network).
It's not elegant to remove Mithril from the DOM, and matter of fact, its source code isn't very elegant to begin with. Imagine spaghetti logic that manipulates quantum references to improbability drives. That's Mithril at the moment, and that's why @lhorie is working on a rewrite (thankfully).
As for m.route.param, that's a pretty simple concept to implement. The biggest problem with routing currently is Unicode. But to be honest, Unicode sucks. All it does is complicate things beyond all known recognition.
(Well...that and make it possible to write an app that supports 15 different languages, but let's ignore that for now...:smile:)
from mithril.js.
Related Issues (20)
- Why are v.attrs passed to oninit() for a child component an empty object? HOT 5
- There is no onsize/onresize lifecycle method HOT 4
- Typescript return type for mithril components HOT 14
- warning 'reuse attrs object' while receiving a component from high order function/component HOT 4
- Broken link to ospec in API page
- make vite the default HOT 4
- Redraw on resolve of async event handler HOT 1
- Please update the Vue comparison HOT 1
- onbeforeremove not being triggered when list element is removed HOT 2
- Form attribute not set in custom element HOT 1
- Add "main" field to package.json
- Need help with "Failed to execute 'insertBefore' on 'Node'" errors. HOT 2
- Is there a bug with dynamically changing svgs? HOT 15
- Current vnode `dom` property is undefined in `onbeforeupdate` HOT 4
- Not getting any events to handle resize HOT 1
- Been a while since the last commit, is Mithril complete? or abandoned? HOT 13
- We have both `main` and `master`. Let's drop both and just rely on a global `next` + version-specific `next`s. HOT 2
- JSFiddle links are broken in CI HOT 2
- htm with Mithril.js HOT 3
- Deprecated dependencies `inflight` and `glob`
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from mithril.js.