Run the demo

This sample demonstrates simple live synchronization of state between server and connected clients.

index.app client-side

index.app
= require(['mho:app', 'mho:std']);
@withAPI('./count.api') {
  |api|
  api.visit();
  @mainContent .. @appendContent(
  `<h1>Hello</h1>
   ${api.visitors}
  `) {
    ||
    hold();
  }
}

count.api server-side

count.api
= require('mho:std');
var date = new Date();
var visitors_total = @ObservableVar(0);
exports.visitors = visitors_total ..
  @transform(total -> 
    "#{total} visitors since #{date}");
exports.visit = function() {
  visitors_total.modify(
    total -> total + 1);
}