-
Notifications
You must be signed in to change notification settings - Fork 502
/
loupe.jsx
125 lines (100 loc) · 3.15 KB
/
loupe.jsx
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
var React = require('react/addons');
window.React = React;
var App = require('./components/app.jsx');
var AmpersandCollection = require('ampersand-collection');
var AmpersandState = require('ampersand-state');
var deval = require('deval');
var CallStack = require('./models/callstack');
var Code = require('./models/code');
var Apis = require('./models/apis');
var CallbackQueue = require('./models/callback-queue');
var RenderQueue = require('./models/render-queue');
var Router = require('./router');
var Modal = require('react-modal');
window.app = {};
window.app.router = new Router();
window.app.store = {
callstack: new CallStack(),
code: new Code(),
apis: new Apis(),
queue: new CallbackQueue(),
renderQueue: new RenderQueue()
};
app.store.code.on('change:codeLines', function () {
});
app.store.code.on('change:encodedSource', function () {
app.router.navigate('?code=' + app.store.code.encodedSource);
});
//app.store.code.on('all', function () {
// console.log('Code event', arguments);
//});
app.store.code.on('node:will-run', function (id, source, invocation) {
app.store.callstack.add({
_id: id,
code: source
});
});
app.store.code.on('node:did-run', function (id, invocation) {
app.store.callstack.pop();
//app.store.callstack.remove(app.store.callstack.at(app.store.call
//app.store.callstack.remove(id + ':' + invocation);
});
app.store.code.on('webapi:started', function (data) {
app.store.apis.add(data, { merge: true });
});
app.store.code.on('callback:shifted', function (id) {
var callback = app.store.queue.get(id);
if (!callback) {
callback = app.store.apis.get(id);
}
app.store.callstack.add({
id: callback.id.toString(),
code: callback.code,
isCallback: true
});
app.store.queue.remove(callback);
});
app.store.code.on('callback:completed', function (id) {
//app.store.callstack.remove(id.toString());
app.store.callstack.pop();
});
app.store.code.on('callback:spawn', function (data) {
var webapi = app.store.apis.get(data.apiId);
if (webapi) {
webapi.trigger('callback:spawned', webapi);
}
app.store.queue.add(data);
});
app.store.apis.on('callback:spawn', function (data) {
app.store.queue.add(data);
});
app.store.code.on('reset-everything', function () {
app.store.renderQueue.reset();
app.store.queue.reset();
app.store.callstack.reset();
app.store.apis.reset();
});
app.store.code.on('paused', function () {
app.store.apis.pause();
});
app.store.code.on('resumed', function () {
app.store.apis.resume();
});
app.store.callstack.on('all', function () {
if (app.store.callstack.length === 0) {
app.store.renderQueue.shift();
}
});
app.store.renderQueue.on('add', function () {
if (app.store.callstack.length === 0) {
app.store.renderQueue.shift();
}
});
if (window.location.origin.match('latentflip.com')) {
window.app.router.history.start({ pushState: true, root: '/loupe/' });
} else {
window.app.router.history.start({ pushState: true });
}
Modal.setAppElement(document.body);
Modal.injectCSS();
React.renderComponent(App(), document.body);