• Stars
    star
    110
  • Rank 315,809 (Top 7 %)
  • Language
    JavaScript
  • License
    MIT License
  • Created over 9 years ago
  • Updated 8 days ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Example of an isomorphic mithril application

Join the chat at https://gitter.im/StephanHoyer/mithril-isomorphic-example

mithril-isomorphic-example

This is an example of an express-based isomorphic mithril application.

It utilizes the architecture descibed in this post. It can be used as a starting point for your isomorphic mithril-based application.

usage

  1. Clone the repo
  2. cd into it
  3. run npm install
  4. run npm start

If you want to run it in production mode (JS minification) just run NODE_ENV=production node server

components

frontend

It's a pretty standard mithril application. For packaging and dependencies we use browserify. The routes are defined in the routes.js. We added two routes for demonstration.

async data for rendering

Rendering async data is demonstrated in the second page. As you can see the route parameters come as vnode.attrs just like in browser mithril app. In order to render async you have to return a promise in the oninit. If this is resolved for all oninits, the response will be sent to the client.

function oninit(vnode) {
  return m.request(apiUrl + 'dog/' + 123).then(function(dog) {
    vnode.state.myDog = dog
  })
}

You can also use route resolver for this. We will add a third route that demonstrates this any time soon.

backend

REST-API

The app contains a basic REST-API based on express.

The API is bound to the base route api/v1/. This can of cause be changed in the server/web.js (also change it on the client side). It's currently just one possible route ('/dog/:id'). In a real application you probably make a config variable with your API-base URL so you can change it in one point.

conclusion

This project should give you a basic idea how to build a isomorphic app with express and mithril. We try to extract as much as possible to modules but stopped at this point, since more abstraction would result in more complicated code. This project is there to be adapted to your special use case. The code-base is pretty small and hopefully understandable.

Fell free to drop us a line in the gitter chat if you have any questions.

More Repositories

1

ng-translate

Translation module for angularjs
JavaScript
34
star
2

tagl

universal hyperscript helper for fancy syntax
JavaScript
22
star
3

magento-lucene

Lucene Search Module for Magento
PHP
22
star
4

how-to-mithril

Collection of example how to do things in mithril
JavaScript
20
star
5

smoke-signal

Simple small functional event observer for the browser and node
JavaScript
17
star
6

classies

Simple css class builder
JavaScript
10
star
7

hedy

Functional ORM
JavaScript
7
star
8

mithril-source-hint

Find file where domnode was created
JavaScript
7
star
9

yss

why style sheets?
JavaScript
6
star
10

modelz

Simple model scheme helper
JavaScript
4
star
11

chuk

Run any arbitrary code before REPL starts
JavaScript
4
star
12

mithril-test

test your mithril modules in a real browser
JavaScript
3
star
13

mithril-talk

Example app (TodoMVC) with mithril in one hour
JavaScript
2
star
14

Mosaik

Asynchronous Node Webframework
CoffeeScript
2
star
15

vandalize

functional minimal framework to create your own validation/sanitation lib
JavaScript
2
star
16

sigmar

Digraph library for node.js
JavaScript
2
star
17

DJsAdmin

Database admin tool based on javascript framework Qooxdoo
JavaScript
2
star
18

sock-channels

Allows to create channels on top of socket connection based on sock.js.
JavaScript
1
star
19

DjangoNestedTabs

Small experiment of building nested navigation with django's class based views
Python
1
star
20

skeleton

Skeleton for express-based webserver
JavaScript
1
star
21

chuk-cb

Chuk plugin which simplifys writing callbacks in REPL session.
JavaScript
1
star
22

git-demo

Demo at Dev-Talk
1
star
23

debounce-as-promised

Promise aware version of debounce
1
star
24

mithril-book

1
star