arohner/foam


Server Side Rendering for Om

License: EPL-1.0

Language: Clojure


Foam

Clojars Project

Circle CI

A hack to add server-side rendering to Om

Assumes you have a working CLJS Om app, and you want to add server-side rendering, without using selenium or node.

Usage

foam provides a minimal reimplementation of the om.core, om.dom namespaces in .clj code. Port your Om components and app-state to .cljc code. In your component namespaces:

(:require #?(:clj [foam.core :as om]
             :cljs [om.core :as om])
          #?(:clj [foam.dom :as dom]
             :cljs [om.dom :as dom]))

Everything should work without needing to modify your component code, with the exception of a few known limitations listed below.

App-State

Like normal Om, your appstate should be an atom wrapping a map or vector. We recommend an app-state constructor function in .cljc, so it's available to both CLJ and CLJS.

Server-side Rendering

In clj, call

(ns foo.bar
  (:require [foam.core :as foam]
            [foam.dom :as dom]))

(let [state (your-app-state)
      cursor (foam/root-cursor state)
      com (foam/build your-component cursor)]
 (dom/render-to-string com)

Serve that in your http response.

Limitations

Lots. This is alpha, though Rasterize is using it in produciton. This list of limitations is not complete.

  • Not all Om protocols have been ported over yet
  • Bugs everywhere

Version Compatiblity

React changed its algorithm for assigning react-ids to elements between 0.14 and 15.0. If you're using react 15 or higher, you'll need foam 0.1.8 or later. Conversely, use foam 0.1.7 for react < 15. Recent Om alphas, such as 1.0.0-alpha40 are known to work with foam.

React < 15 | >= 15 Om 0.9 | 1.0.0-alpha40 foam 0.1.7 | 0.1.8

License

Copyright © 2015 Allen Rohner

Distributed under the Eclipse Public License either version 1.0 or (at your option) any later version.

Contains code adapted from Om

Contains code adapted from hiccup

Contains code adapted from sablono

Project Statistics

Sourcerank 5
Repository Size 58.6 KB
Stars 56
Forks 4
Watchers 6
Open issues 1
Dependencies 0
Contributors 2
Tags 9
Created
Last updated
Last pushed

Top Contributors See all

Allen Rohner Joel Sánchez López

Packages Referencing this Repo

arohner:foam
server-side rendering for Om
Latest release 0.1.8 - Updated - 56 stars
arohner/foam
server-side rendering for Om
Latest release 0.1.8 - Updated - 56 stars

Recent Tags See all

0.1.8 July 22, 2016
0.1.7 March 08, 2016
0.1.6 February 20, 2016
0.1.5 February 13, 2016
0.1.4 December 30, 2015
0.1.3 November 28, 2015
0.1.2 November 24, 2015
0.1.1 November 24, 2015
0.1.0 November 24, 2015

Something wrong with this page? Make a suggestion

Last synced: 2016-07-26 12:46:30 UTC

Login to resync this repository