This is an automated email from the ASF dual-hosted git repository. jtulach pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/incubator-netbeans-html4j.git
commit 8cb4dbf8dab3d1a429595ce2898a01ea454e5977 Author: Jaroslav Tulach <[email protected]> AuthorDate: Thu Feb 14 05:33:50 2019 +0100 Notify change in all known presenters --- .../main/java/org/netbeans/html/ko4j/Knockout.java | 29 ++++++++++++++++- .../org/netbeans/html/ko4j/DoubleViewTest.java | 38 +++++++++++++++------- 2 files changed, 55 insertions(+), 12 deletions(-) diff --git a/ko4j/src/main/java/org/netbeans/html/ko4j/Knockout.java b/ko4j/src/main/java/org/netbeans/html/ko4j/Knockout.java index f83534f..ac91bcc 100644 --- a/ko4j/src/main/java/org/netbeans/html/ko4j/Knockout.java +++ b/ko4j/src/main/java/org/netbeans/html/ko4j/Knockout.java @@ -18,8 +18,11 @@ */ package org.netbeans.html.ko4j; +import java.io.Closeable; +import java.io.IOException; import java.util.HashMap; import java.util.Map; +import java.util.concurrent.Executor; import net.java.html.js.JavaScriptBody; import net.java.html.js.JavaScriptResource; import net.java.html.json.Model; @@ -144,7 +147,31 @@ final class Knockout { funcs[index].call(data, ev); } - final void valueHasMutated(String propertyName, Object oldValue, Object newValue) { + final void valueHasMutated(final String propertyName, Object oldValue, Object newValue) { + for (Map.Entry<Fn.Presenter, Object> e : objs.entrySet()) { + Fn.Presenter p = e.getKey(); + final Object o = e.getValue(); + if (p != Fn.activePresenter()) { + if (p instanceof Executor) { + ((Executor) p).execute(new Runnable() { + @Override + public void run() { + valueHasMutated(o, propertyName, null, null); + } + }); + } else { + Closeable c = Fn.activate(p); + try { + valueHasMutated(o, propertyName, null, null); + } finally { + try { + c.close(); + } catch (IOException ex) { + } + } + } + } + } valueHasMutated(js(), propertyName, oldValue, newValue); } diff --git a/ko4j/src/test/java/org/netbeans/html/ko4j/DoubleViewTest.java b/ko4j/src/test/java/org/netbeans/html/ko4j/DoubleViewTest.java index 7232bc2..83a48ed 100644 --- a/ko4j/src/test/java/org/netbeans/html/ko4j/DoubleViewTest.java +++ b/ko4j/src/test/java/org/netbeans/html/ko4j/DoubleViewTest.java @@ -41,20 +41,24 @@ import org.testng.annotations.Test; @Property(name = "message", type = String.class) }) public class DoubleViewTest { + private static String set; + @Function static void change(DoubleView model) { - model.setMessage("Modified"); + assertNotNull(set); + model.setMessage(set); + set = null; } - + DoubleView doubleView; private WebView view1; private WebView view2; - + @BeforeMethod public void initializeViews() throws Exception { final JFXPanel panel = new JFXPanel(); final JFXPanel p2 = new JFXPanel(); - + final CountDownLatch initViews = new CountDownLatch(1); Platform.runLater(new Runnable() { @Override @@ -64,15 +68,15 @@ public class DoubleViewTest { } }); initViews.await(); - + doubleView = new DoubleView(); doubleView.setMessage("Initialized"); final URL page = DoubleViewTest.class.getResource("double.html"); assertNotNull(page, "double.html found"); - - + + final CountDownLatch view1Init = new CountDownLatch(1); final CountDownLatch view2Init = new CountDownLatch(1); Platform.runLater(new Runnable() { @@ -98,11 +102,11 @@ public class DoubleViewTest { view1Init.await(); view2Init.await(); } - + private void displayFrame(JFXPanel panel, JFXPanel p2) { view1 = displayWebView(panel); view2 = displayWebView(p2); - + JFrame f = new JFrame(); f.getContentPane().setLayout(new FlowLayout()); f.getContentPane().add(panel); @@ -119,7 +123,7 @@ public class DoubleViewTest { panel.setScene(scene); return webView; } - + @Test public void synchronizationOfViews() throws Throwable { final CountDownLatch cdl = new CountDownLatch(1); @@ -130,6 +134,14 @@ public class DoubleViewTest { try { assertMessages("In view one", view1, "Initialized"); assertMessages("In view two", view2, "Initialized"); + set = "Change1"; + clickButton(view1); + assertMessages("In view one", view1, "Change1"); + assertMessages("In view two", view2, "Change1"); + set = "Change2"; + clickButton(view2); + assertMessages("In view one", view1, "Change2"); + assertMessages("In view two", view2, "Change2"); } catch (Throwable t) { arr[0] = t; } finally { @@ -142,7 +154,7 @@ public class DoubleViewTest { throw arr[0]; } } - + @AfterMethod public void waitABit() throws Exception { } @@ -154,4 +166,8 @@ public class DoubleViewTest { Object prop = v.getEngine().executeScript("document.getElementById('property').innerHTML"); assertEquals(prop, expected, msg + " 'property' check"); } + + private void clickButton(WebView v) { + v.getEngine().executeScript("document.getElementById('change').click()"); + } } --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected] For further information about the NetBeans mailing lists, visit: https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists
