Skip to content

Commit

Permalink
Fix WebIO deprecations, add Project.toml. (#16)
Browse files Browse the repository at this point in the history
Fix WebIO deprecations, add Project.toml.
  • Loading branch information
twavv committed Jun 10, 2019
2 parents 1dd7097 + ba46216 commit d9e9af0
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 17 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@
assets/knockout.js
assets/knockout_punches.js
deps/build.log

Manifest.toml
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,6 @@ branches:
- /^v[0-9]+\.[0-9]+\.[0-9]+$/ # version tags
script:
- if [[ -a .git/shallow ]]; then git fetch --unshallow; fi
- $TESTCMD -e 'using Pkg; Pkg.clone(pwd()); Pkg.build("Knockout"); Pkg.test("Knockout"; coverage=true)'
- $TESTCMD -e 'using Pkg; Pkg.build(); Pkg.test("Knockout"; coverage=true)'
after_success:
- julia -e coverage.jl
22 changes: 22 additions & 0 deletions Project.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
name = "Knockout"
uuid = "bcebb21b-c2e3-54f8-a781-646b90f6d2cc"
license = "MIT"
version = "0.2.3"

[deps]
JSExpr = "97c1335a-c9c5-57fe-bc5d-ec35cebe8660"
JSON = "682c06a0-de6a-54ab-a142-c8b1cf79cde6"
Observables = "510215fc-4207-5dde-b226-833fc4488ee2"
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
WebIO = "0f1e0344-ec1d-5b48-a673-e5cf874b6c29"

[compat]
WebIO = ">= 0.8.0"
julia = "0.7, 1"

[extras]
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
Blink = "ad839575-38b3-5650-b840-f874b8c74a25"

[targets]
test = ["Blink", "Test"]
5 changes: 0 additions & 5 deletions REQUIRE

This file was deleted.

25 changes: 16 additions & 9 deletions src/Knockout.jl
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@ You can pass functions that you want available in the Knockout scope as keyword
`knockout` E.g. `knockout(...; methods=Dict(:sayhello=>@js function(){ alert("hello!") }))`
"""
function knockout(template, data=Dict(), extra_js = js""; computed = [], methods = [])
id = WebIO.newid("knockout-component")
widget = Scope(id;
imports=Any["knockout" => knockout_js, "knockout_punches" => knockout_punches_js]
)
widget.dom = template
widget = Scope(imports=[
"knockout" => knockout_js,
"knockout_punches" => knockout_punches_js,
])
widget(template)
ko_data = Dict()
watches = Dict()
for (k, v) in data
Expand Down Expand Up @@ -75,23 +75,30 @@ function knockout(template, data=Dict(), extra_js = js""; computed = [], methods
function (ko, koPunches) {
ko.punches.enableAll();
ko.bindingHandlers.numericValue = {
init : function(element, valueAccessor, allBindings, data, context) {
init: function(element, valueAccessor, allBindings, data, context) {
var stringified = ko.observable(ko.unwrap(valueAccessor()));
stringified.subscribe(function(value) {
var val = parseFloat(value);
if (!isNaN(val)) {
valueAccessor()(val);
}
})
});
valueAccessor().subscribe(function(value) {
var str = JSON.stringify(value);
if ((str == "0") && (["-0", "-0."].indexOf(stringified()) >= 0))
return;
if (["null", ""].indexOf(str) >= 0)
return;
stringified(str);
})
ko.applyBindingsToNode(element, { value: stringified, valueUpdate: allBindings.get('valueUpdate')}, context);
});
ko.applyBindingsToNode(
element,
{
value: stringified,
valueUpdate: allBindings.get('valueUpdate'),
},
context,
);
}
};
var json_data = $ko_data;
Expand Down
1 change: 0 additions & 1 deletion test/REQUIRE

This file was deleted.

0 comments on commit d9e9af0

Please sign in to comment.