-
-
Save dashed/c5a4db4b1b2942c37365 to your computer and use it in GitHub Desktop.
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
var mori = require("mori"); | |
function Calendar(appointments, previousCalendar) { | |
appointments = appointments; | |
var cal = {}; | |
cal.add = function(appointment) { | |
var withAppointments = mori.conj(appointments, appointment); | |
return Calendar(withAppointments, cal); | |
}; | |
cal.upcoming = function(start, n) { | |
var futureAppointments = mori.filter(function(a) { | |
return a.date >= start; | |
}, appointments); | |
return mori.take(n, futureAppointments); | |
}; | |
cal.undo = function() { | |
return previousCalendar || Calendar(); | |
}; | |
return cal; | |
} | |
var myCalendar = Calendar().add({ | |
title: 'X', | |
date: Date.parse('2014-07-11T18:00') // update this | |
}).add({ | |
title: 'Y', | |
date: Date.parse('2014-07-11T19:00') // update this | |
}).add({ | |
title: 'Z', | |
date: Date.parse('2014-07-11T20:00') // update this | |
}); | |
var nextAppointments = myCalendar.upcoming(Date.now(), 2); | |
console.log( | |
mori.map(function(a) { | |
return a.title; | |
}, nextAppointments).toString() // we need to convert the Mori object some how (.toString for ease) | |
); // => ("Z" "Y") | |
var previousCalendar = myCalendar.undo().undo(); | |
var appointments = previousCalendar.upcoming(Date.now(), 2); | |
console.log( | |
mori.map(function(a) { | |
return a.title; | |
}, appointments).toString() | |
); // => ("X") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment