I am trying to run ClojureScript on node.js
app1.js target code: working:
var rx = require("./lib/rx/rx.node.js");
var moment = require("./lib/moment/moment.js");
var timeStream = new rx.Observable.interval(300)
.subscribe(function(index)
{
console.log(moment().format("dddd, MMMM Do YYYY, h:mm:ss a"));
});
core.cljs my try so far:
(ns rxcljs.core
(:use [cljs.nodejs :only [require]])
)
(def rx (require "./lib/rx/rx.node.js"))
(def moment (require "./lib/moment/moment.js"))
(-> rx
(.Observable)
(.interval 300)
(.subscribe #(->> (->(moment)
(.format "dddd, MMMM Do YYYY, h:mm:ss a" )
)
(.log js/console)
)
)
)
app.js the actual compile output: not working
.....
.....
cljs.nodejs = {};
cljs.nodejs.require = require;
cljs.nodejs.process = process;
cljs.core.string_print = cljs.nodejs.require.call(null, "util").print;
var rxcljs = {core:{}};
rxcljs.core.rx = cljs.nodejs.require.call(null, "./lib/rx/rx.node.js");
rxcljs.core.moment = cljs.nodejs.require.call(null, "./lib/moment/moment.js");
rxcljs.core.rx.Observable().interval(300).subscribe(function() {
return console.log(rxcljs.core.moment.call(null).format("dddd, MMMM Do YYYY, h:mm:ss a"))
});
The error:
/...../rxcljs/app.js:12726
rxcljs.core.rx.Observable().interval(300).subscribe(function() {
^
TypeError: Cannot call method 'interval' of undefined
Please advice.
Answer EDIT
Thanks to Michal:
(ns rxcljs.core
(:use [cljs.nodejs :only [require]])
)
(def log #(.log js/console %))
(def rx (require "./lib/rx/rx.node.js"))
(def moment (require "./lib/moment/moment.js"))
(-> rx .-Observable
(.interval 300)
(.subscribe #(->> (-> (moment)
(.format "dddd, MMMM Do YYYY, h:mm:ss a")
)
(log)
)
)
)
rx interval working properly, moment format output is still weired though.