Domanda

I'm using Lamina to implement Functional reactive programming (FRP).

As a starter, I try to code a very simple clock in order to understand the library basics.

According to the Lamina 0.5.0-rc4 API documentation, there is lamina.time API: http://ideolalia.com/lamina/lamina.time.html#var-now

I want to implement a very simple clock where:

  • Interval of every second as Observable time Streaming Collection/List/Seq (I don't quite understand the difference yet) (EDIT: now I understood it's called Channels on Lamina)

  • Now as Observable Streaming data

  • Println Now on every second (subscribe or for-each Observable time Collection)

Any feedback is welcome. Thanks.

EDIT: I quit.

After some research, I conclude the best way to code FRP is ClojureScript with RxJs(ReactiveExtention from MS).

See the example Code for ClojureScript + RxJs + node.js in my related Qestion Here: ClojureScript on node.js, code

È stato utile?

Soluzione

You could try Bacon.js, a successor to Rx.js created after its author complained about its obscure API. Bacon.js is very clean and can integrate with jQuery, Backbone.js, AngularJS, and even Node.js. Basically you can wrap any kind of events into a Bacon's event stream and start do wonderful things with them.

Bonus : you could even try yolk, described as "A thin Clojurescript wrapper around bacon.js".

-- edit : quick typo fixes

Altri suggerimenti

I found a good article: http://adambard.com/blog/why-clojure-part-2-async-magic/

-LAMINA: ADVANCED ASYNCHRONOUS PROCESSING

(ns example.helloperiodically
  (:require [lamina.core :as lamina]))

(def ch (lamina/periodically 1000 (fn [] "Hello World!")))

(def loop-forever (comp doall repeatedly))

(defn consumer []
   (loop-forever
     (fn [] (println @(lamina/read-channel ch)))))

(defn main []
  (-> (Thread. consumer) .start))

Why not try ProAct.js - it implements both the functional and object-oriented approaches. It has a package for node.js (proact.js) - it stable and well tested.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top