Skip to content

nous-consulting/meteor-persistent-state

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Installation:

`meteor add nous:state`

Usage

Template.mytemplate.initState({
  someVar: 'default value',
  selectedColor: undefined
});
  
Template.mytemplate.helpers({
  getCar: function () {
    color = Template.instance().vars.selectedColor;
    return Cars.findOne({country: @country, color: color});
  }
});

Template.mytemlpate.events({
  'click .selectColor': function (e, tpl) {
    tpl.vars.selectedColor = e.target.value;
  }
});

or you can use our methods and CoffeScript for more beatifull code:

Template.mytemplate.initState
  someVar: 'default value'
  selectedColor: undefined
  
Template.mytemplate.methods
  getCar: ->
    Cars.findOne
      country: @context.country
      color: @vars.selectedColor})

Template.mytemlpate.events
  'click .selectColor': (e, tpl) ->
    tpl.vars.selectedColor = e.target.value

Persistence and Hooks

If you want to store/restore to/from database, you can use onStateUpdated and onStateRequested template hooks. Also you can use nous:tabmanager if you want to persist your state (all tree) into database each time URL is changed, to have possibility to restore it when you back.

About

Persistent state for Meteor (nous:state)

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published