1.1 --- a/json/src/main/java/org/apidesign/html/json/spi/Proto.java Fri Jan 10 11:26:38 2014 +0100
1.2 +++ b/json/src/main/java/org/apidesign/html/json/spi/Proto.java Thu Jan 30 11:36:32 2014 +0100
1.3 @@ -70,6 +70,7 @@
1.4 private final net.java.html.BrwsrCtx context;
1.5 private boolean locked;
1.6 private org.netbeans.html.json.impl.Bindings ko;
1.7 + private Proto onMutated;
1.8
1.9 Proto(Object obj, Type type, BrwsrCtx context) {
1.10 this.obj = obj;
1.11 @@ -115,11 +116,36 @@
1.12 *@param propName name of the changed property
1.13 */
1.14 public void valueHasMutated(String propName) {
1.15 + if (onMutated != null) {
1.16 + onMutated.valueHasMutated(propName);
1.17 + }
1.18 if (ko != null) {
1.19 ko.valueHasMutated(propName);
1.20 + final String[] names = type.propertyNames;
1.21 + for (int i = 0; i < names.length; i++) {
1.22 + if (names[i].equals(propName)) {
1.23 + type.onChange(obj, i);
1.24 + }
1.25 + }
1.26 }
1.27 }
1.28
1.29 + /** Allows another prototype to be notified when a value is mutated using
1.30 + * {@link #valueHasMutated(java.lang.String)} method of this object.
1.31 + * This method can be called only once. It is primarily useful for
1.32 + * support of {@link Model}s on <code>enum</code>s.
1.33 + *
1.34 + * @param m object which {@link #valueHasMutated(java.lang.String)}
1.35 + * method should be called when there is a change in a property
1.36 + * of this proto object.
1.37 + * @since 0.8
1.38 + */
1.39 + public void onValueHasMutated(Proto m) {
1.40 + assert m != null;
1.41 + assert onMutated == null;
1.42 + onMutated = m;
1.43 + }
1.44 +
1.45 /** Initializes the associated model in the current {@link #getContext() context}.
1.46 * In case of <em>knockout.js</em> technology, applies given bindings
1.47 * of the current model to the <em>body</em> element of the page.
1.48 @@ -662,5 +688,5 @@
1.49 return type.cast(val);
1.50 }
1.51
1.52 - }
1.53 + } // end of Type
1.54 }