Skip to content

Latest commit

 

History

History
54 lines (43 loc) · 1.23 KB

es5.md

File metadata and controls

54 lines (43 loc) · 1.23 KB

ES5 Syntax

Although the examples and documentation show megalith being used with modern ES syntax, you can still use achieve the same results in environments that only support ES5.

var megalith = require('megalith');

// Create constructor
function App() {
  megalith.Store.call(this);

  this.initialState = {
    version: 1,
    messages: ['a', 'b']
  };
}

// Extend Store
App.prototype = Object.create(megalith.Store.prototype);
App.prototype.constructor = App;

// Define action
megalith.action.define(App.prototype, 'bump', function() {
  return {
    version: this.version + 1,
    messages: this.messages
  };
});

var app = new App();
app.version; // => 1
app.bump();
app.version; // => 2



Documentation