diff options
| author | s-ol <s-ol@users.noreply.github.com> | 2018-08-03 22:11:15 +0000 |
|---|---|---|
| committer | s-ol <s-ol@users.noreply.github.com> | 2018-08-03 22:11:15 +0000 |
| commit | f8d89aee2d5ce87380aaf3b985ae28759ff3abb9 (patch) | |
| tree | dae5bc9300cec89b24c6be75aa8494f1e23af0e2 | |
| parent | add play-tags (diff) | |
| download | mmm-f8d89aee2d5ce87380aaf3b985ae28759ff3abb9.tar.gz mmm-f8d89aee2d5ce87380aaf3b985ae28759ff3abb9.zip | |
add \transform to reactivevar
| -rw-r--r-- | app/component.moon | 4 | ||||
| -rw-r--r-- | app/test_component.moon | 15 | ||||
| m--------- | dist | 0 |
3 files changed, 19 insertions, 0 deletions
diff --git a/app/component.moon b/app/component.moon index fc29f8c..4f1d0c0 100644 --- a/app/component.moon +++ b/app/component.moon @@ -1,5 +1,7 @@ { :document } = js.global +warn = warn or -> print + -- convert anything to a DOM Node -- val must be one of: -- * DOM Node (instanceof window.Node) @@ -39,6 +41,8 @@ class ReactiveVar get: => @value + transform: (transform) => @set transform @get! + subscribe: (callback) => with -> @listeners[callback] = nil @listeners[callback] = callback diff --git a/app/test_component.moon b/app/test_component.moon index 5298175..538368a 100644 --- a/app/test_component.moon +++ b/app/test_component.moon @@ -78,6 +78,21 @@ run_test "passed old value as well", -> reactive\set 3 assert done, "expected to reach the end" +run_test "provides transform shorthand", -> + local done + + reactive = ReactiveVar 1 + reactive\subscribe coroutine.wrap (next, last) -> + assert last == 1, "expected last:1 to be 1" + next, last = coroutine.yield! + assert last == 2, "expected last:2 to be 2" + done = true + + add_one = (a) -> a + 1 + reactive\transform add_one + reactive\transform add_one + assert done, "expected to reach the end" + run_test "#subscribe returns function to unsubscribe", -> calls = 0 diff --git a/dist b/dist -Subproject 7244d9a6fc301962748cb69a2ffd8cb277a99d9 +Subproject 4168b2385c2442b4940f60d678a1b8e646bb3a1 |
