Last active
August 29, 2015 14:17
-
-
Save dgellow/ab46728c8f60b959e4b5 to your computer and use it in GitHub Desktop.
Wisp vs Javascript comparison
This file contains hidden or 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
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() | |
}); | |
} | |
}); | |
} |
This file contains hidden or 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
(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))) |
This file contains hidden or 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
// | |
// 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