Advertisement
Guest User

Reactive Transform Attempt

a guest
Jul 18th, 2014
264
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. # test.html
  2.  
  3. <template name="test">
  4.     <p>Time test</p>
  5.     {{#each times}}
  6.         <p>Completion time: {{complete}}</p>
  7.         <p>Time to complete: {{timeLeft}}</p>
  8.     {{/each}}
  9. </template>
  10.  
  11. # test.coffee
  12.  
  13. @Test = new Meteor.Collection('test')
  14.  
  15. if Meteor.isServer
  16.     currentDate = new Date()
  17.     finishDate = new Date(currentDate.getTime() + 360000)
  18.     Test.insert { complete: finishDate }
  19.  
  20. if Meteor.isClient
  21.     Template.test.times = Test.find({},{
  22.         transform: (doc) ->
  23.            doc.timeLeft = (new Date(doc.complete.getTime()
  24.                - new Date().getTime()))
  25.                .getTime() / 1000 #number of seconds
  26.            doc
  27.     })
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement