-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Extracted remote logic to github file
- Loading branch information
Showing
3 changed files
with
38 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,49 +1,24 @@ | ||
(ns haxlife.core | ||
(:require-macros [cljs.core.async.macros :refer [go]]) | ||
(:require [om.next :as om :include-macros true] | ||
[haxlife.components.window :as window] | ||
[goog.dom :as gdom] | ||
[clojure.string :as string] | ||
[haxlife.query :as query] | ||
[cljs.core.async :refer [<! >! put! chan]]) | ||
(:import [goog Uri] | ||
[goog.net Jsonp])) | ||
[haxlife.github :as github] | ||
[cljs.core.async :refer [chan]])) | ||
|
||
(enable-console-print!) | ||
|
||
(def base-url | ||
"http://en.wikipedia.org/w/api.php?action=opensearch&format=json&search=") | ||
|
||
(defn jsonp | ||
([uri] (jsonp (chan) uri)) | ||
([c uri] | ||
(let [gjsonp (Jsonp. (Uri. uri))] | ||
(.send gjsonp nil #(put! c %)) | ||
c))) | ||
|
||
(def app-state (atom)) | ||
(def send-chan (chan)) | ||
|
||
(defn search-loop [c] | ||
(go | ||
(loop [[query cb] (<! c)] | ||
(let [[_ results] (<! (jsonp (str base-url query)))] | ||
(cb {:code results})) | ||
(recur (<! c))))) | ||
|
||
(defn send-to-chan [c] | ||
(fn [{:keys [search]} cb] | ||
(when search | ||
(let [{[search] :children} (om/query->ast search) | ||
query (get-in search [:params :query])] | ||
(put! c [query cb]))))) | ||
(github/code-loop send-chan) | ||
|
||
(def reconciler | ||
(om/reconciler {:state app-state | ||
:parser (om/parser {:read query/read :mutate query/mutate}) | ||
:send (send-to-chan send-chan) | ||
:remotes [:remote :search]})) | ||
:send (github/send-to-chan send-chan) | ||
:remotes [:remote :code]})) | ||
|
||
|
||
(search-loop send-chan) | ||
|
||
(om/add-root! reconciler window/Window (gdom/getElement "app")) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters