Reactive-coffee is a Coffeescript reactive library (link) that makes it easier to create rich, reusable web components. It automate almost everything in reactive web app. I love the fact that Reactive-coffee offers this powerful reactive programming paradigm that play well with Meteor, you don't even need to write a html template.
Make sure you have Meteor and Meteorite installed.
meteor add mrt:reactive-coffee
See official documentation here. We also built a Meteor demo site: Reactive-Coffee-Demo.meteor.com
- rx.meteor.find( collection, selector, options)
- returns
rx.array
, and each element in the array is an regular object - use
.all()
to fetch all the elements in therx.array
- returns
- rx.meteor.findOne( collection, selector, options)
- returns
rx.cell
- use
.get()
to fetch the element in therx.cell
- returns
collection should be an instance of Meteor.Collection.
Please refer to official api to learn more about rx.array
and rx.cell
, doc.
Highly recommended for coffeescript
lovers.
-
- Initialization and importTags
Meteor.startup ->
window.bind = rx.bind # shorthand for bind function
rx.rxt.importTags() # import p, span, div, etc. tags as functions into the namespace
-
- Populate Meteor.Collection instance to a
rx.array
orrx.cell
, e.g.
- Populate Meteor.Collection instance to a
todos = rx.meteor.find Todo, {}, {sort: {created: -1}} # returns rx.array
latestTodo = rx.meteor.findOne Todo, {}, {sort: {created: -1}} # returns rx.cell
-
- Hook/Bind to Html elements
$('foo').prepend(
span {}, bind -> [latestTodo.get().title]
div {}, bind -> todos.all().map (todo) ->
div todo.title
)
-
- CRUD operation on Meteor.Collection will automatically reflect on
rx.array
orrx.cell
instance. For example:
- CRUD operation on Meteor.Collection will automatically reflect on
Todo.update todo._id, {$set: {isCompleted: true}}
Thanks for yang/reactive-coffee