forked from selsamman/amorphic-bindster
-
Notifications
You must be signed in to change notification settings - Fork 0
/
bindster-amorphic.js
62 lines (47 loc) · 1.74 KB
/
bindster-amorphic.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
var __ver = __ver || 0;
if (typeof(controller) == 'undefined')
var controller = null;
if (typeof(bindster) == 'undefined')
var bindster = null;
// Bind bindster to semotus
amorphic.establishClientSession(
"Controller", __ver,
// Establish a new session whether first time or because of expiry / server restart
function (newController, sessionExpiration) {
if (controller && typeof(controller.shutdown) == "function")
controller.shutdown();
controller = newController;
console.log("creating bindster binding");
if (!bindster) {
bindster = new Bindster(controller, null, controller, null, true);
bindster.alert = function (msg) {
//controller.serverLog(msg);
alert(msg);
}
if (typeof(controller.clientInit) == "function")
controller.clientInit(sessionExpiration);
bindster.start();
} else {
bindster.setModel(controller)
bindster.setController(controller);
if (typeof(controller.clientInit) == "function")
controller.clientInit(sessionExpiration);
controller.refresh(1);
}
},
// Rerender after xhr request received
function (hadChanges) {
controller.refresh(1, hadChanges);
},
// When a new version is detected pop up "about to be refreshed" and
// then reload the document after 5 seconds.
function () {
controller.amorphicStatus = 'reloading';
controller.refresh(1);
setTimeout(function () {document.location.reload(true)}, 3000);
},
// If communication lost pop up dialog
function () {
controller.amorphicStatus = 'offline';
}
);