Skip to content

Instantly share code, notes, and snippets.

@dgellow
Last active August 29, 2015 14:17
Show Gist options
  • Save dgellow/ab46728c8f60b959e4b5 to your computer and use it in GitHub Desktop.
Save dgellow/ab46728c8f60b959e4b5 to your computer and use it in GitHub Desktop.
Wisp vs Javascript comparison
if (Meteor.isServer) {
Meteor.publish('documents', function() {
return Documents.find({});
});
Meteor.startup(function() {
var doc = Documents.findOne({title: 'Initial document'});
if (!doc) {
Documents.insert({
title 'Initial document',
content: [],
createdAt: new Date()
});
}
});
}
(defn find-all [col]
(fn [] (.find col)))
(defn insert-default-doc []
(let [doc (.find-one Documents {:title "Initial document"})]
(if (not doc)
(.insert Documents
{:title "Initial document"
:content []
:created-at (new Date)}))))
(if (.-server? Meteor)
(do
(.publish Meteor "documents" (find-all Documents))
(.startup Meteor insert-default-doc)))
//
// Result of wisp compilation
//
var findAll = exports.findAll = function findAll(col) {
return function () {
return col.find();
};
};
var insertDefaultDoc = exports.insertDefaultDoc = function insertDefaultDoc() {
return function () {
var docø1 = Documents.findOne({ 'title': 'Initial document' });
return !docø1 ? Documents.insert({
'title': 'Initial document',
'content': [],
'created-at': new Date()
}) : void 0;
}.call(this);
};
Meteor.isServer ? (function () {
Meteor.publish('documents', findAll(Documents));
return Meteor.startup(insertDefaultDoc);
})() : void 0;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment