Documentation

Sample code

Sample code

function AddonSample_create() {  
    var presenter = function () {};  
    var clickCounter = 0;  
    presenter.run = function(view, model) {  
        presenter.$view = $(view);  
        presenter.model = model;  
        var $button = $(view).find('button'),  
            $counter = $(view).find('.sample-addon-clicks-counter');  
        $button.click(function (event) {  
             event.preventDefault();  
             clickCounter++;  
             $counter.text('Count: ' + clickCounter);  
        });  
    };  
    presenter.createPreview = function(view, model) {  
      $(view).find('button').click(function (event) {  
        event.preventDefault();  
      });  
    };  
    presenter.getState = function () {  
      return JSON.stringify({  
        clickCounter: clickCounter  
      });  
    };  
    presenter.setState = function (state) {  
     var parsedState = JSON.parse(state),  
        $counter = presenter.$view.find('.sample-addon-clicks-counter');  
       clickCounter = parsedState.clickCounter;  
       $counter.text('Count: ' + clickCounter);  
    };  
    return presenter;  
}