Skip to content

Instantly share code, notes, and snippets.

2015-01-29 Unofficial Relay FAQ

Compilation of questions and answers about Relay from React.js Conf.

Disclaimer: I work on Relay at Facebook. Relay is a complex system on which we're iterating aggressively. I'll do my best here to provide accurate, useful answers, but the details are subject to change. I may also be wrong. Feedback and additional questions are welcome.

What is Relay?

Relay is a new framework from Facebook that provides data-fetching functionality for React applications. It was announced at React.js Conf (January 2015).

@borkdude
borkdude / tooltip-om.clj
Last active August 29, 2015 14:06
Add tooltip to Om DOM components showing displayname and contents of cursor and local state
;;; To add a tooltip, write (tooltip {:className "foo"}) instead of #js {:className "foo"}
;;; You can simplify this and just show what you need: #js {:title (pr-str (om/...))}.
;;; testfoo.core (cljs)
(ns testfoo.core
(:require-macros [testfoo.macros :refer (tooltip)])
(:require [om.core :as om :include-macros true]
[om.dom :as dom :include-macros true]
[cljs.reader :as reader]))
var Dialog = React.createClass({
render: function() {
// 1) render nothing, this way the DOM diff will never try to do
// anything to it again, and we get a node to mess with
return React.DOM.div();
},
componentDidMount: function() {
// 2) do DOM lib stuff
this.node = this.getDOMNode();
@robert-stuttaford
robert-stuttaford / start.cljs
Created August 21, 2014 13:07
Nicely grouped transaction logging in JS Console for Om apps
(ns app
(:require [om.core :as om :include-macros true]))
(defn log-tx [tx-data root-cursor]
(let [{:keys [path old-value new-value]} tx-data
c js/console]
(doto c (.group (str "TRANSACTION " path)) (.groupCollapsed "OLD"))
(prn (pr-str old-value))
(doto c (.groupEnd) (.group "NEW"))
(prn (pr-str new-value))
(require '[clojure.core.async :as a])
(def xform (comp (map inc)
(filter even?)
(dedupe)
(flatmap range)
(partition-all 3)
(partition-by #(< (apply + %) 7))
(flatmap flatten)
(random-sample 1.0)
@noprompt
noprompt / mdiff.clj
Last active August 29, 2015 14:04
Map diff based on clj-diff.
(require '[clj-diff.core :as d])
(require '[clojure.set :as set])
(defn mdiff [ma mb base-path]
(let [es (reduce
(fn [m k]
(let [vb (get mb k)
kp (conj base-path k)]
(if-let [va (get ma k)]
(if (not= va vb)
@karlwestin
karlwestin / errorhandler.js
Created July 31, 2014 09:22
simple window.onerror handler
function errorHandler(msg, url, line, column, err) {
// firefox bug to watch for 5 arg error handler
// https://bugzilla.mozilla.org/show_bug.cgi?id=630464
/*
* most browsers don't give column number,
* but chrome can do it sometimes
*/
if(typeof column == "object") {
err = column;
@ohpauleez
ohpauleez / service.clj
Last active August 29, 2015 14:03
Pedestal 0.3.0 example with SSE
;; In Pedestal 0.3.1, you won't have to use an atom.
;; You'll pass the channel into the SSE creation function (instead of it passing one back to you)
(def event-ch (atom nil))
(defn home-page
[request]
(ring-resp/response "Hello World!"))
(defroutes routes
[[["/" {:get home-page}