@@ -24,11 +24,11 @@ You can pass functions that you want available in the Knockout scope as keyword
24
24
`knockout` E.g. `knockout(...; methods=Dict(:sayhello=>@js function(){ alert("hello!") }))`
25
25
"""
26
26
function knockout (template, data= Dict (), extra_js = js "" ; computed = [], methods = [])
27
- id = WebIO . newid ( " knockout-component " )
28
- widget = Scope (id;
29
- imports = Any[ " knockout " => knockout_js, " knockout_punches" => knockout_punches_js]
30
- )
31
- widget. dom = template
27
+ widget = Scope (imports = [
28
+ " knockout " => knockout_js,
29
+ " knockout_punches" => knockout_punches_js,
30
+ ] )
31
+ widget ( template)
32
32
ko_data = Dict ()
33
33
watches = Dict ()
34
34
for (k, v) in data
@@ -75,23 +75,30 @@ function knockout(template, data=Dict(), extra_js = js""; computed = [], methods
75
75
function (ko , koPunches ) {
76
76
ko .punches .enableAll ();
77
77
ko .bindingHandlers .numericValue = {
78
- init : function (element , valueAccessor , allBindings , data , context ) {
78
+ init : function (element , valueAccessor , allBindings , data , context ) {
79
79
var stringified = ko .observable (ko .unwrap (valueAccessor ()));
80
80
stringified .subscribe (function (value ) {
81
81
var val = parseFloat (value);
82
82
if (! isNaN (val)) {
83
83
valueAccessor ()(val);
84
84
}
85
- })
85
+ });
86
86
valueAccessor ().subscribe (function (value ) {
87
87
var str = JSON .stringify (value);
88
88
if ((str == " 0" ) && ([" -0" , " -0." ].indexOf (stringified ()) >= 0 ))
89
89
return ;
90
90
if ([" null" , " " ].indexOf (str) >= 0 )
91
91
return ;
92
92
stringified (str);
93
- })
94
- ko .applyBindingsToNode (element, { value: stringified, valueUpdate: allBindings .get (' valueUpdate' )}, context);
93
+ });
94
+ ko .applyBindingsToNode (
95
+ element,
96
+ {
97
+ value: stringified,
98
+ valueUpdate: allBindings .get (' valueUpdate' ),
99
+ },
100
+ context,
101
+ );
95
102
}
96
103
};
97
104
var json_data = $ko_data;
0 commit comments