Created
October 4, 2018 02:26
-
-
Save back2dos/aacbf9673b950eb46db98d3ba144a2bc to your computer and use it in GitHub Desktop.
Coconut data example.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html lang="en"> | |
<head> | |
<meta charset="utf-8"/> | |
<title>Example</title> | |
</head> | |
<body> | |
<input type="text" name="text" value="Ford Prefect"> | |
<input type="number" name="type" value="42"> | |
<input type="checkbox" name="visible" checked> | |
<script src="test.js"></script> | |
</body> | |
</html> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import js.Browser.*; | |
using StringTools; | |
class Data implements coconut.data.Model { | |
@:observable var text:String; | |
@:observable var type:Int; | |
@:observable var visible:Bool; | |
@:transition function receiveUpdate(delta) | |
return @patch delta; | |
} | |
class Test { | |
static function main() { | |
function getInput(name:String):js.html.InputElement | |
return cast document.querySelector('input[name=$name]'); | |
function grabData() | |
return { | |
text: getInput('text').value.trim(), | |
type: Std.int(getInput('type').valueAsNumber), | |
visible: getInput('visible').checked, | |
}; | |
var d = new Data(grabData()); | |
d.observables.text.bind(function (value) trace('text is now $value')); | |
//Or more fun stuff: | |
var message = tink.state.Observable.auto(function () | |
return '${d.text} now has type ${d.type} and is '+if (d.visible) "visible" else "invisible" | |
); | |
var output = document.createDivElement(); | |
document.body.appendChild(output); | |
message.bind(function (s) output.textContent = s); | |
document.body.addEventListener("input", function (e:js.html.Event) { | |
e.preventDefault(); | |
d.receiveUpdate(grabData()); | |
}); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-dce full | |
-main Test | |
-lib coconut.data | |
-js test.js |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Generated by Haxe 4.0.0 (git build development @ 3018ab109) | |
(function () { "use strict"; | |
function $extend(from, fields) { | |
function Inherit() {} Inherit.prototype = from; var proto = new Inherit(); | |
for (var name in fields) proto[name] = fields[name]; | |
if( fields.toString !== Object.prototype.toString ) proto.toString = fields.toString; | |
return proto; | |
} | |
var HxOverrides = function() { }; | |
HxOverrides.__name__ = true; | |
HxOverrides.strDate = function(s) { | |
var _g = s.length; | |
switch(_g) { | |
case 8: | |
var k = s.split(":"); | |
var d = new Date(); | |
d["setTime"](0); | |
d["setUTCHours"](k[0]); | |
d["setUTCMinutes"](k[1]); | |
d["setUTCSeconds"](k[2]); | |
return d; | |
case 10: | |
var k1 = s.split("-"); | |
return new Date(k1[0],k1[1] - 1,k1[2],0,0,0); | |
case 19: | |
var k2 = s.split(" "); | |
var y = k2[0].split("-"); | |
var t = k2[1].split(":"); | |
return new Date(y[0],y[1] - 1,y[2],t[0],t[1],t[2]); | |
default: | |
throw new js__$Boot_HaxeError("Invalid date format : " + s); | |
} | |
}; | |
HxOverrides.cca = function(s,index) { | |
var x = s.charCodeAt(index); | |
if(x != x) { | |
return undefined; | |
} | |
return x; | |
}; | |
HxOverrides.substr = function(s,pos,len) { | |
if(len == null) { | |
len = s.length; | |
} else if(len < 0) { | |
if(pos == 0) { | |
len = s.length + len; | |
} else { | |
return ""; | |
} | |
} | |
return s.substr(pos,len); | |
}; | |
HxOverrides.remove = function(a,obj) { | |
var i = a.indexOf(obj); | |
if(i == -1) { | |
return false; | |
} | |
a.splice(i,1); | |
return true; | |
}; | |
Math.__name__ = true; | |
var Reflect = function() { }; | |
Reflect.__name__ = true; | |
Reflect.fields = function(o) { | |
var a = []; | |
if(o != null) { | |
var hasOwnProperty = Object.prototype.hasOwnProperty; | |
for( var f in o ) { | |
if(f != "__id__" && f != "hx__closures__" && hasOwnProperty.call(o,f)) { | |
a.push(f); | |
} | |
} | |
} | |
return a; | |
}; | |
var StringTools = function() { }; | |
StringTools.__name__ = true; | |
StringTools.isSpace = function(s,pos) { | |
var c = HxOverrides.cca(s,pos); | |
if(!(c > 8 && c < 14)) { | |
return c == 32; | |
} else { | |
return true; | |
} | |
}; | |
StringTools.ltrim = function(s) { | |
var l = s.length; | |
var r = 0; | |
while(r < l && StringTools.isSpace(s,r)) ++r; | |
if(r > 0) { | |
return HxOverrides.substr(s,r,l - r); | |
} else { | |
return s; | |
} | |
}; | |
StringTools.rtrim = function(s) { | |
var l = s.length; | |
var r = 0; | |
while(r < l && StringTools.isSpace(s,l - r - 1)) ++r; | |
if(r > 0) { | |
return HxOverrides.substr(s,0,l - r); | |
} else { | |
return s; | |
} | |
}; | |
StringTools.trim = function(s) { | |
return StringTools.ltrim(StringTools.rtrim(s)); | |
}; | |
var coconut_data_Model = function() { }; | |
coconut_data_Model.__name__ = true; | |
var Data = function(initial) { | |
var this1 = new tink_state__$State_SimpleState(initial.text,null,null); | |
this.__coco_text = this1; | |
var this11 = new tink_state__$State_SimpleState(initial.type,null,null); | |
this.__coco_type = this11; | |
var this12 = new tink_state__$State_SimpleState(initial.visible,null,null); | |
this.__coco_visible = this12; | |
var this13 = new tink_state__$State_SimpleState(0,null,null); | |
this.__coco_transitionCount = this13; | |
this.errorTrigger = tink_core__$Signal_Signal_$Impl_$.trigger(); | |
this.transitionErrors = this.errorTrigger; | |
this.observables = { text : this.__coco_text, type : this.__coco_type, visible : this.__coco_visible, isInTransition : tink_state__$Observable_Observable_$Impl_$.map(this.__coco_transitionCount,tink_state__$Observable_Transform_$Impl_$.plain(function(c) { | |
return c > 0; | |
}))}; | |
}; | |
Data.__name__ = true; | |
Data.__interfaces__ = [coconut_data_Model]; | |
Data.prototype = { | |
receiveUpdate: function(delta) { | |
var _gthis = this; | |
var ret = tink_core__$Promise_Promise_$Impl_$.ofOutcome(tink_core_Outcome.Success(delta)); | |
var sync = true; | |
var done = false; | |
ret.handle(function(o) { | |
done = true; | |
if(!sync) { | |
var tmp = tink_state__$State_State_$Impl_$.get_value(_gthis.__coco_transitionCount) - 1; | |
_gthis.__coco_transitionCount.set(tmp); | |
} | |
switch(o[1]) { | |
case 0: | |
var v = o[2]; | |
_gthis.__cocoupdate(v); | |
break; | |
case 1: | |
var e = o[2]; | |
tink_core__$Callback_CallbackList_$Impl_$.invoke(_gthis.errorTrigger.handlers,e); | |
break; | |
} | |
}); | |
if(!done) { | |
sync = false; | |
} | |
if(!sync) { | |
this.__coco_transitionCount.set(tink_state__$State_State_$Impl_$.get_value(this.__coco_transitionCount) + 1); | |
} | |
return tink_core__$Promise_Promise_$Impl_$.next(ret,function(_) { | |
return tink_core__$Promise_Promise_$Impl_$.ofOutcome(tink_core_Outcome.Success(tink_core_Noise.Noise)); | |
}); | |
} | |
,get_text: function() { | |
return tink_state__$State_State_$Impl_$.get_value(this.__coco_text); | |
} | |
,get_type: function() { | |
return tink_state__$State_State_$Impl_$.get_value(this.__coco_type); | |
} | |
,get_visible: function() { | |
return tink_state__$State_State_$Impl_$.get_value(this.__coco_visible); | |
} | |
,__cocoupdate: function(delta) { | |
var this1 = { }; | |
var sparse = this1; | |
var delta1 = delta; | |
var _g = 0; | |
var _g1 = Reflect.fields(delta1); | |
while(_g < _g1.length) { | |
var k = _g1[_g]; | |
++_g; | |
var this11 = new Array(1); | |
var this2 = this11; | |
var ret = this2; | |
ret[0] = delta1[k]; | |
sparse[k] = ret; | |
} | |
var delta2 = sparse; | |
if(delta2.text != null) { | |
this.__coco_text.set(delta2.text[0]); | |
} | |
if(delta2.type != null) { | |
this.__coco_type.set(delta2.type[0]); | |
} | |
if(delta2.visible != null) { | |
this.__coco_visible.set(delta2.visible[0]); | |
} | |
} | |
}; | |
var Test = function() { }; | |
Test.__name__ = true; | |
Test.main = function() { | |
var getInput = function(name) { | |
return window.document.querySelector("input[name=" + name + "]"); | |
}; | |
var grabData = function() { | |
return { text : StringTools.trim(getInput("text").value), type : getInput("type").valueAsNumber | 0, visible : getInput("visible").checked}; | |
}; | |
var d = new Data(grabData()); | |
tink_state__$Observable_Observable_$Impl_$.bind(d.observables.text,null,function(value) { | |
console.log("Test.hx:26:","text is now " + value); | |
}); | |
var this1 = { f : function() { | |
return "" + d.get_text() + " now has type " + d.get_type() + " and is " + (d.get_visible() ? "visible" : "invisible"); | |
}}; | |
var message = tink_state__$Observable_Observable_$Impl_$.auto(this1); | |
var output = window.document.createElement("div"); | |
window.document.body.appendChild(output); | |
tink_state__$Observable_Observable_$Impl_$.bind(message,null,function(s) { | |
output.textContent = s; | |
}); | |
window.document.body.addEventListener("input",function(e) { | |
e.preventDefault(); | |
var tmp = grabData(); | |
d.receiveUpdate(tmp); | |
}); | |
}; | |
var haxe_IMap = function() { }; | |
haxe_IMap.__name__ = true; | |
var haxe_Timer = function(time_ms) { | |
var me = this; | |
this.id = setInterval(function() { | |
me.run(); | |
},time_ms); | |
}; | |
haxe_Timer.__name__ = true; | |
haxe_Timer.delay = function(f,time_ms) { | |
var t = new haxe_Timer(time_ms); | |
t.run = function() { | |
t.stop(); | |
f(); | |
}; | |
return t; | |
}; | |
haxe_Timer.prototype = { | |
stop: function() { | |
if(this.id == null) { | |
return; | |
} | |
clearInterval(this.id); | |
this.id = null; | |
} | |
,run: function() { | |
} | |
}; | |
var haxe_ds_List = function() { | |
this.length = 0; | |
}; | |
haxe_ds_List.__name__ = true; | |
haxe_ds_List.prototype = { | |
push: function(item) { | |
var x = new haxe_ds__$List_ListNode(item,this.h); | |
this.h = x; | |
if(this.q == null) { | |
this.q = x; | |
} | |
this.length++; | |
} | |
,first: function() { | |
if(this.h == null) { | |
return null; | |
} else { | |
return this.h.item; | |
} | |
} | |
,pop: function() { | |
if(this.h == null) { | |
return null; | |
} | |
var x = this.h.item; | |
this.h = this.h.next; | |
if(this.h == null) { | |
this.q = null; | |
} | |
this.length--; | |
return x; | |
} | |
}; | |
var haxe_ds__$List_ListNode = function(item,next) { | |
this.item = item; | |
this.next = next; | |
}; | |
haxe_ds__$List_ListNode.__name__ = true; | |
var haxe_ds_ObjectMap = function() { | |
this.h = { __keys__ : { }}; | |
}; | |
haxe_ds_ObjectMap.__name__ = true; | |
haxe_ds_ObjectMap.__interfaces__ = [haxe_IMap]; | |
haxe_ds_ObjectMap.prototype = { | |
set: function(key,value) { | |
var id = key.__id__ || (key.__id__ = ++haxe_ds_ObjectMap.count); | |
this.h[id] = value; | |
this.h.__keys__[id] = key; | |
} | |
}; | |
var js__$Boot_HaxeError = function(val) { | |
Error.call(this); | |
this.val = val; | |
if(Error.captureStackTrace) { | |
Error.captureStackTrace(this,js__$Boot_HaxeError); | |
} | |
}; | |
js__$Boot_HaxeError.__name__ = true; | |
js__$Boot_HaxeError.wrap = function(val) { | |
if((val instanceof Error)) { | |
return val; | |
} else { | |
return new js__$Boot_HaxeError(val); | |
} | |
}; | |
js__$Boot_HaxeError.__super__ = Error; | |
js__$Boot_HaxeError.prototype = $extend(Error.prototype,{ | |
}); | |
var tink_core__$Callback_Callback_$Impl_$ = {}; | |
tink_core__$Callback_Callback_$Impl_$.__name__ = true; | |
tink_core__$Callback_Callback_$Impl_$.invoke = function(this1,data) { | |
if(tink_core__$Callback_Callback_$Impl_$.depth < 1000) { | |
tink_core__$Callback_Callback_$Impl_$.depth++; | |
this1(data); | |
tink_core__$Callback_Callback_$Impl_$.depth--; | |
} else { | |
var _e = this1; | |
var f = function(data1) { | |
tink_core__$Callback_Callback_$Impl_$.invoke(_e,data1); | |
}; | |
var data2 = data; | |
tink_core__$Callback_Callback_$Impl_$.defer(function() { | |
f(data2); | |
}); | |
} | |
}; | |
tink_core__$Callback_Callback_$Impl_$.fromNiladic = function(f) { | |
return function(_) { | |
f(); | |
}; | |
}; | |
tink_core__$Callback_Callback_$Impl_$.defer = function(f) { | |
haxe_Timer.delay(f,0); | |
}; | |
var tink_core__$Callback_LinkObject = function() { }; | |
tink_core__$Callback_LinkObject.__name__ = true; | |
var tink_core__$Callback_SimpleLink = function(f) { | |
this.f = f; | |
}; | |
tink_core__$Callback_SimpleLink.__name__ = true; | |
tink_core__$Callback_SimpleLink.__interfaces__ = [tink_core__$Callback_LinkObject]; | |
tink_core__$Callback_SimpleLink.prototype = { | |
dissolve: function() { | |
if(this.f != null) { | |
this.f(); | |
this.f = null; | |
} | |
} | |
}; | |
var tink_core__$Callback_ListCell = function(cb,list) { | |
if(cb == null) { | |
throw new js__$Boot_HaxeError("callback expected but null received"); | |
} | |
this.cb = cb; | |
this.list = list; | |
}; | |
tink_core__$Callback_ListCell.__name__ = true; | |
tink_core__$Callback_ListCell.__interfaces__ = [tink_core__$Callback_LinkObject]; | |
tink_core__$Callback_ListCell.prototype = { | |
clear: function() { | |
this.list = null; | |
this.cb = null; | |
} | |
,dissolve: function() { | |
var _g = this.list; | |
if(_g != null) { | |
var v = _g; | |
this.clear(); | |
HxOverrides.remove(v,this); | |
} | |
} | |
}; | |
var tink_core__$Callback_CallbackList_$Impl_$ = {}; | |
tink_core__$Callback_CallbackList_$Impl_$.__name__ = true; | |
tink_core__$Callback_CallbackList_$Impl_$.add = function(this1,cb) { | |
var node = new tink_core__$Callback_ListCell(cb,this1); | |
this1.push(node); | |
return node; | |
}; | |
tink_core__$Callback_CallbackList_$Impl_$.invoke = function(this1,data) { | |
var _g = 0; | |
var _g1 = this1.slice(); | |
while(_g < _g1.length) { | |
var cell = _g1[_g]; | |
++_g; | |
if(cell.cb != null) { | |
tink_core__$Callback_Callback_$Impl_$.invoke(cell.cb,data); | |
} | |
} | |
}; | |
tink_core__$Callback_CallbackList_$Impl_$.clear = function(this1) { | |
var _g = 0; | |
var _g1 = this1.splice(0,this1.length); | |
while(_g < _g1.length) { | |
var cell = _g1[_g]; | |
++_g; | |
cell.clear(); | |
} | |
}; | |
var tink_core_TypedError = function() { }; | |
tink_core_TypedError.__name__ = true; | |
var tink_core__$Future_FutureObject = function() { }; | |
tink_core__$Future_FutureObject.__name__ = true; | |
var tink_core_Noise = { __ename__ : true, __constructs__ : ["Noise"] }; | |
tink_core_Noise.Noise = ["Noise",0]; | |
tink_core_Noise.Noise.__enum__ = tink_core_Noise; | |
var tink_core__$Lazy_LazyObject = function() { }; | |
tink_core__$Lazy_LazyObject.__name__ = true; | |
var tink_core__$Lazy_LazyConst = function(value) { | |
this.value = value; | |
}; | |
tink_core__$Lazy_LazyConst.__name__ = true; | |
tink_core__$Lazy_LazyConst.__interfaces__ = [tink_core__$Lazy_LazyObject]; | |
tink_core__$Lazy_LazyConst.prototype = { | |
get: function() { | |
return this.value; | |
} | |
,map: function(f) { | |
var _gthis = this; | |
return new tink_core__$Lazy_LazyFunc(function() { | |
return f(_gthis.value); | |
}); | |
} | |
}; | |
var tink_core__$Future_SyncFuture = function(value) { | |
this.value = value; | |
}; | |
tink_core__$Future_SyncFuture.__name__ = true; | |
tink_core__$Future_SyncFuture.__interfaces__ = [tink_core__$Future_FutureObject]; | |
tink_core__$Future_SyncFuture.prototype = { | |
flatMap: function(f) { | |
var l = this.value.map(f); | |
return new tink_core__$Future_SimpleFuture(function(cb) { | |
return l.get().handle(cb); | |
}); | |
} | |
,handle: function(cb) { | |
tink_core__$Callback_Callback_$Impl_$.invoke(cb,this.value.get()); | |
return null; | |
} | |
,gather: function() { | |
return this; | |
} | |
}; | |
var tink_core__$Future_Future_$Impl_$ = {}; | |
tink_core__$Future_Future_$Impl_$.__name__ = true; | |
tink_core__$Future_Future_$Impl_$.flatten = function(f) { | |
return new tink_core__$Future_NestedFuture(f); | |
}; | |
var tink_core__$Future_SimpleFuture = function(f) { | |
this.f = f; | |
}; | |
tink_core__$Future_SimpleFuture.__name__ = true; | |
tink_core__$Future_SimpleFuture.__interfaces__ = [tink_core__$Future_FutureObject]; | |
tink_core__$Future_SimpleFuture.prototype = { | |
handle: function(callback) { | |
return this.f(callback); | |
} | |
,flatMap: function(f) { | |
var f1 = f; | |
var _gthis = this; | |
return tink_core__$Future_Future_$Impl_$.flatten(new tink_core__$Future_SimpleFuture(function(cb) { | |
return _gthis.f(function(v) { | |
var tmp = f1(v); | |
tink_core__$Callback_Callback_$Impl_$.invoke(cb,tmp); | |
}); | |
})); | |
} | |
,gather: function() { | |
if(this.gathered != null) { | |
return this.gathered; | |
} else { | |
return this.gathered = tink_core_FutureTrigger.gatherFuture(this); | |
} | |
} | |
}; | |
var tink_core__$Future_NestedFuture = function(outer) { | |
this.outer = outer; | |
}; | |
tink_core__$Future_NestedFuture.__name__ = true; | |
tink_core__$Future_NestedFuture.__interfaces__ = [tink_core__$Future_FutureObject]; | |
tink_core__$Future_NestedFuture.prototype = { | |
flatMap: function(f) { | |
var ret = this.outer.flatMap(function(inner) { | |
var ret1 = inner.flatMap(f); | |
return ret1.gather(); | |
}); | |
return ret.gather(); | |
} | |
,gather: function() { | |
if(this.gathered != null) { | |
return this.gathered; | |
} else { | |
return this.gathered = tink_core_FutureTrigger.gatherFuture(this); | |
} | |
} | |
,handle: function(cb) { | |
var ret = null; | |
ret = this.outer.handle(function(inner) { | |
ret = inner.handle(function(result) { | |
tink_core__$Callback_Callback_$Impl_$.invoke(cb,result); | |
}); | |
}); | |
return ret; | |
} | |
}; | |
var tink_core_FutureTrigger = function() { | |
var this1 = []; | |
this.list = this1; | |
}; | |
tink_core_FutureTrigger.__name__ = true; | |
tink_core_FutureTrigger.__interfaces__ = [tink_core__$Future_FutureObject]; | |
tink_core_FutureTrigger.gatherFuture = function(f) { | |
var op = null; | |
var this1 = new tink_core__$Future_SimpleFuture(function(cb) { | |
if(op == null) { | |
op = new tink_core_FutureTrigger(); | |
f.handle($bind(op,op.trigger)); | |
f = null; | |
} | |
return op.handle(cb); | |
}); | |
return this1; | |
}; | |
tink_core_FutureTrigger.prototype = { | |
handle: function(callback) { | |
var _g = this.list; | |
if(_g == null) { | |
tink_core__$Callback_Callback_$Impl_$.invoke(callback,this.result); | |
return null; | |
} else { | |
var v = _g; | |
return tink_core__$Callback_CallbackList_$Impl_$.add(v,callback); | |
} | |
} | |
,flatMap: function(f) { | |
var _g = this.list; | |
if(_g == null) { | |
return f(this.result); | |
} else { | |
var v = _g; | |
var ret = new tink_core_FutureTrigger(); | |
tink_core__$Callback_CallbackList_$Impl_$.add(this.list,function(v1) { | |
f(v1).handle($bind(ret,ret.trigger)); | |
}); | |
return ret; | |
} | |
} | |
,gather: function() { | |
return this; | |
} | |
,trigger: function(result) { | |
if(this.list == null) { | |
return false; | |
} else { | |
var list = this.list; | |
this.list = null; | |
this.result = result; | |
tink_core__$Callback_CallbackList_$Impl_$.invoke(list,result); | |
tink_core__$Callback_CallbackList_$Impl_$.clear(list); | |
return true; | |
} | |
} | |
}; | |
var tink_core__$Lazy_LazyFunc = function(f) { | |
this.f = f; | |
}; | |
tink_core__$Lazy_LazyFunc.__name__ = true; | |
tink_core__$Lazy_LazyFunc.__interfaces__ = [tink_core__$Lazy_LazyObject]; | |
tink_core__$Lazy_LazyFunc.prototype = { | |
get: function() { | |
if(this.f != null) { | |
this.result = this.f(); | |
this.f = null; | |
} | |
return this.result; | |
} | |
,map: function(f) { | |
var _gthis = this; | |
return new tink_core__$Lazy_LazyFunc(function() { | |
var tmp = _gthis.get(); | |
return f(tmp); | |
}); | |
} | |
}; | |
var tink_core_Outcome = { __ename__ : true, __constructs__ : ["Success","Failure"] }; | |
tink_core_Outcome.Success = function(data) { var $x = ["Success",0,data]; $x.__enum__ = tink_core_Outcome; return $x; }; | |
tink_core_Outcome.Failure = function(failure) { var $x = ["Failure",1,failure]; $x.__enum__ = tink_core_Outcome; return $x; }; | |
var tink_core_MPair = function(a,b) { | |
this.a = a; | |
this.b = b; | |
}; | |
tink_core_MPair.__name__ = true; | |
var tink_core__$Promise_Promise_$Impl_$ = {}; | |
tink_core__$Promise_Promise_$Impl_$.__name__ = true; | |
tink_core__$Promise_Promise_$Impl_$.next = function(this1,f,gather) { | |
if(gather == null) { | |
gather = true; | |
} | |
var ret = this1.flatMap(function(o) { | |
switch(o[1]) { | |
case 0: | |
var d = o[2]; | |
return f(d); | |
case 1: | |
var f1 = o[2]; | |
return new tink_core__$Future_SyncFuture(new tink_core__$Lazy_LazyConst(tink_core_Outcome.Failure(f1))); | |
} | |
}); | |
if(gather) { | |
return ret.gather(); | |
} else { | |
return ret; | |
} | |
}; | |
tink_core__$Promise_Promise_$Impl_$.ofOutcome = function(o) { | |
return new tink_core__$Future_SyncFuture(new tink_core__$Lazy_LazyConst(o)); | |
}; | |
var tink_core__$Signal_Signal_$Impl_$ = {}; | |
tink_core__$Signal_Signal_$Impl_$.__name__ = true; | |
tink_core__$Signal_Signal_$Impl_$.trigger = function() { | |
return new tink_core_SignalTrigger(); | |
}; | |
var tink_core_SignalObject = function() { }; | |
tink_core_SignalObject.__name__ = true; | |
var tink_core_SignalTrigger = function() { | |
this.handlers = []; | |
}; | |
tink_core_SignalTrigger.__name__ = true; | |
tink_core_SignalTrigger.__interfaces__ = [tink_core_SignalObject]; | |
var tink_state__$Observable_Observable_$Impl_$ = {}; | |
tink_state__$Observable_Observable_$Impl_$.__name__ = true; | |
tink_state__$Observable_Observable_$Impl_$.get_value = function(this1) { | |
return tink_state__$Observable_Observable_$Impl_$.measure(this1).a; | |
}; | |
tink_state__$Observable_Observable_$Impl_$.map = function(this1,f) { | |
return tink_state__$Observable_Observable_$Impl_$.create(function() { | |
var m = tink_state__$Observable_Observable_$Impl_$.measure(this1); | |
var this2 = new tink_core_MPair(f(m.a),m.b); | |
var this3 = this2; | |
return this3; | |
}); | |
}; | |
tink_state__$Observable_Observable_$Impl_$.measure = function(this1) { | |
var before = tink_state__$Observable_Observable_$Impl_$.stack.first(); | |
tink_state__$Observable_Observable_$Impl_$.stack.push(this1); | |
var p = this1.poll(); | |
var _g = (before instanceof tink_state__$Observable_AutoObservable) ? before : null; | |
if(_g != null) { | |
var v = _g; | |
v.subscribe(p.b); | |
} | |
tink_state__$Observable_Observable_$Impl_$.stack.pop(); | |
return p; | |
}; | |
tink_state__$Observable_Observable_$Impl_$.bind = function(this1,options,cb) { | |
var cb1; | |
if(options == null) { | |
cb1 = cb; | |
} else if(options.comparator == null) { | |
cb1 = cb; | |
} else { | |
var equal = options.comparator; | |
var isFirst = true; | |
var last = null; | |
cb1 = function(data) { | |
if(isFirst) { | |
isFirst = false; | |
tink_core__$Callback_Callback_$Impl_$.invoke(cb,data); | |
} else if(!equal(last,data)) { | |
tink_core__$Callback_Callback_$Impl_$.invoke(cb,data); | |
} | |
last = data; | |
}; | |
} | |
if(options == null) { | |
var scheduled = false; | |
var active = true; | |
var updated = null; | |
var link = null; | |
var update = function() { | |
if(active) { | |
var next = tink_state__$Observable_Observable_$Impl_$.measure(this1); | |
tink_core__$Callback_Callback_$Impl_$.invoke(cb1,next.a); | |
scheduled = false; | |
link = next.b.handle(updated); | |
} | |
}; | |
var doSchedule = function() { | |
if(scheduled) { | |
return; | |
} | |
scheduled = true; | |
tink_state__$Observable_Observable_$Impl_$.schedule(update); | |
}; | |
updated = tink_core__$Callback_Callback_$Impl_$.fromNiladic(doSchedule); | |
doSchedule(); | |
var this2 = new tink_core__$Callback_SimpleLink(function() { | |
if(active) { | |
active = false; | |
if(link != null) { | |
link.dissolve(); | |
} | |
} | |
}); | |
return this2; | |
} else if(options.direct == null) { | |
var scheduled1 = false; | |
var active1 = true; | |
var updated1 = null; | |
var link1 = null; | |
var update1 = function() { | |
if(active1) { | |
var next1 = tink_state__$Observable_Observable_$Impl_$.measure(this1); | |
tink_core__$Callback_Callback_$Impl_$.invoke(cb1,next1.a); | |
scheduled1 = false; | |
link1 = next1.b.handle(updated1); | |
} | |
}; | |
var doSchedule1 = function() { | |
if(scheduled1) { | |
return; | |
} | |
scheduled1 = true; | |
tink_state__$Observable_Observable_$Impl_$.schedule(update1); | |
}; | |
updated1 = tink_core__$Callback_Callback_$Impl_$.fromNiladic(doSchedule1); | |
doSchedule1(); | |
var this3 = new tink_core__$Callback_SimpleLink(function() { | |
if(active1) { | |
active1 = false; | |
if(link1 != null) { | |
link1.dissolve(); | |
} | |
} | |
}); | |
return this3; | |
} else if(options.direct == false) { | |
var scheduled2 = false; | |
var active2 = true; | |
var updated2 = null; | |
var link2 = null; | |
var update2 = function() { | |
if(active2) { | |
var next2 = tink_state__$Observable_Observable_$Impl_$.measure(this1); | |
tink_core__$Callback_Callback_$Impl_$.invoke(cb1,next2.a); | |
scheduled2 = false; | |
link2 = next2.b.handle(updated2); | |
} | |
}; | |
var doSchedule2 = function() { | |
if(scheduled2) { | |
return; | |
} | |
scheduled2 = true; | |
tink_state__$Observable_Observable_$Impl_$.schedule(update2); | |
}; | |
updated2 = tink_core__$Callback_Callback_$Impl_$.fromNiladic(doSchedule2); | |
doSchedule2(); | |
var this4 = new tink_core__$Callback_SimpleLink(function() { | |
if(active2) { | |
active2 = false; | |
if(link2 != null) { | |
link2.dissolve(); | |
} | |
} | |
}); | |
return this4; | |
} else { | |
var link3 = null; | |
var update3 = null; | |
update3 = function(_) { | |
var next3 = tink_state__$Observable_Observable_$Impl_$.measure(this1); | |
tink_core__$Callback_Callback_$Impl_$.invoke(cb1,next3.a); | |
link3 = next3.b.handle(update3); | |
}; | |
var update4 = update3; | |
update4(tink_core_Noise.Noise); | |
var this5 = new tink_core__$Callback_SimpleLink(function() { | |
if(link3 != null) { | |
link3.dissolve(); | |
} | |
}); | |
return this5; | |
} | |
}; | |
tink_state__$Observable_Observable_$Impl_$.schedule = function(f) { | |
var _g = tink_state__$Observable_Observable_$Impl_$.scheduled; | |
if(_g == null) { | |
f(); | |
} else { | |
var v = _g; | |
v.push(f); | |
tink_state__$Observable_Observable_$Impl_$.scheduleUpdate(); | |
} | |
}; | |
tink_state__$Observable_Observable_$Impl_$.scheduleUpdate = function() { | |
if(!tink_state__$Observable_Observable_$Impl_$.isScheduled) { | |
tink_state__$Observable_Observable_$Impl_$.isScheduled = true; | |
if(tink_state__$Observable_Observable_$Impl_$.hasRAF) { | |
window.requestAnimationFrame(function(_) { | |
tink_state__$Observable_Observable_$Impl_$.scheduledRun(); | |
}); | |
} else { | |
tink_core__$Callback_Callback_$Impl_$.defer(tink_state__$Observable_Observable_$Impl_$.scheduledRun); | |
} | |
} | |
}; | |
tink_state__$Observable_Observable_$Impl_$.scheduledRun = function() { | |
tink_state__$Observable_Observable_$Impl_$.isScheduled = false; | |
tink_state__$Observable_Observable_$Impl_$.updatePending(); | |
}; | |
tink_state__$Observable_Observable_$Impl_$.updatePending = function(maxSeconds) { | |
if(maxSeconds == null) { | |
maxSeconds = .01; | |
} | |
var end = new Date().getTime() / 1000 + maxSeconds; | |
while(true) { | |
var old = tink_state__$Observable_Observable_$Impl_$.scheduled; | |
tink_state__$Observable_Observable_$Impl_$.scheduled = []; | |
var _g = 0; | |
while(_g < old.length) { | |
var o = old[_g]; | |
++_g; | |
o(); | |
} | |
if(!(tink_state__$Observable_Observable_$Impl_$.scheduled.length > 0 && new Date().getTime() / 1000 < end)) { | |
break; | |
} | |
} | |
if(tink_state__$Observable_Observable_$Impl_$.scheduled.length > 0) { | |
tink_state__$Observable_Observable_$Impl_$.scheduleUpdate(); | |
return true; | |
} else { | |
return false; | |
} | |
}; | |
tink_state__$Observable_Observable_$Impl_$.create = function(f) { | |
return new tink_state__$Observable_SimpleObservable(f); | |
}; | |
tink_state__$Observable_Observable_$Impl_$.auto = function(f) { | |
return new tink_state__$Observable_AutoObservable(f); | |
}; | |
var tink_state_ObservableObject = function() { }; | |
tink_state_ObservableObject.__name__ = true; | |
var tink_state__$Observable_SimpleObservable = function(f) { | |
this._poll = f; | |
}; | |
tink_state__$Observable_SimpleObservable.__name__ = true; | |
tink_state__$Observable_SimpleObservable.__interfaces__ = [tink_state_ObservableObject]; | |
tink_state__$Observable_SimpleObservable.prototype = { | |
resetCache: function(_) { | |
this.cache = null; | |
} | |
,poll: function() { | |
var count = 0; | |
var last = null; | |
while(this.cache == null) { | |
var cache = this.cache = this._poll(); | |
if(last == cache) { | |
throw new js__$Boot_HaxeError("Polling loops on the same value"); | |
} | |
last = cache; | |
cache.b.handle($bind(this,this.resetCache)); | |
if(count++ >= 100) { | |
throw new js__$Boot_HaxeError("Polling not concluded after 100 iterations"); | |
} | |
} | |
return this.cache; | |
} | |
}; | |
var tink_state__$Observable_Transform_$Impl_$ = {}; | |
tink_state__$Observable_Transform_$Impl_$.__name__ = true; | |
tink_state__$Observable_Transform_$Impl_$.plain = function(f) { | |
var this1 = f; | |
return this1; | |
}; | |
var tink_state__$Observable_AutoObservable = function(comp) { | |
this.subscriptions = new haxe_ds_ObjectMap(); | |
var _gthis = this; | |
tink_state__$Observable_SimpleObservable.call(this,function() { | |
_gthis.subscriptions = new haxe_ds_ObjectMap(); | |
_gthis.trigger = new tink_core_FutureTrigger(); | |
var this1 = new tink_core_MPair(comp.f(),_gthis.trigger); | |
var this2 = this1; | |
return this2; | |
}); | |
}; | |
tink_state__$Observable_AutoObservable.__name__ = true; | |
tink_state__$Observable_AutoObservable.__super__ = tink_state__$Observable_SimpleObservable; | |
tink_state__$Observable_AutoObservable.prototype = $extend(tink_state__$Observable_SimpleObservable.prototype,{ | |
subscribe: function(change) { | |
if(this.subscriptions.h.__keys__[change.__id__] == null) { | |
var this1 = this.subscriptions; | |
var v = change.handle(($_=this.trigger,$bind($_,$_.trigger))); | |
this1.set(change,v); | |
} | |
} | |
}); | |
var tink_state__$State_State_$Impl_$ = {}; | |
tink_state__$State_State_$Impl_$.__name__ = true; | |
tink_state__$State_State_$Impl_$.get_value = function(this1) { | |
return tink_state__$Observable_Observable_$Impl_$.get_value(this1); | |
}; | |
var tink_state__$State_StateObject = function() { }; | |
tink_state__$State_StateObject.__name__ = true; | |
tink_state__$State_StateObject.__interfaces__ = [tink_state_ObservableObject]; | |
var tink_state__$State_SimpleState = function(value,isEqual,guard) { | |
this.value = value; | |
this.isEqual = isEqual; | |
this.guard = guard; | |
this.arm(); | |
}; | |
tink_state__$State_SimpleState.__name__ = true; | |
tink_state__$State_SimpleState.__interfaces__ = [tink_state__$State_StateObject]; | |
tink_state__$State_SimpleState.prototype = { | |
poll: function() { | |
return this.next; | |
} | |
,arm: function() { | |
this.trigger = new tink_core_FutureTrigger(); | |
var this1 = new tink_core_MPair(this.value,this.trigger); | |
var this2 = this1; | |
this.next = this2; | |
} | |
,set: function(value) { | |
if(this.guard != null) { | |
value = this.guard(value,this.value); | |
} | |
var b = this.value; | |
if(this.isEqual == null ? value != b : !this.isEqual(value,b)) { | |
this.value = value; | |
var last = this.trigger; | |
this.arm(); | |
last.trigger(tink_core_Noise.Noise); | |
} | |
} | |
}; | |
var $_, $fid = 0; | |
function $bind(o,m) { if( m == null ) return null; if( m.__id__ == null ) m.__id__ = $fid++; var f; if( o.hx__closures__ == null ) o.hx__closures__ = {}; else f = o.hx__closures__[m.__id__]; if( f == null ) { f = m.bind(o); o.hx__closures__[m.__id__] = f; } return f; } | |
String.__name__ = true; | |
Array.__name__ = true; | |
Date.__name__ = ["Date"]; | |
haxe_ds_ObjectMap.count = 0; | |
Object.defineProperty(js__$Boot_HaxeError.prototype,"message",{ get : function() { | |
return String(this.val); | |
}}); | |
tink_core__$Callback_Callback_$Impl_$.depth = 0; | |
tink_state__$Observable_Observable_$Impl_$.stack = new haxe_ds_List(); | |
tink_state__$Observable_Observable_$Impl_$.scheduled = []; | |
tink_state__$Observable_Observable_$Impl_$.hasRAF = typeof window != 'undefined' && 'requestAnimationFrame' in window; | |
tink_state__$Observable_Observable_$Impl_$.isScheduled = false; | |
Test.main(); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment