This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.
Summary: | Add method for initializing technology | ||
---|---|---|---|
Product: | platform | Reporter: | maxnitribitt <maxnitribitt> |
Component: | Html4j | Assignee: | Jaroslav Tulach <jtulach> |
Status: | RESOLVED FIXED | ||
Severity: | normal | CC: | apireviews |
Priority: | P4 | Keywords: | API_REVIEW_FAST |
Version: | 8.1 | ||
Hardware: | PC | ||
OS: | Mac OS X | ||
Issue Type: | DEFECT | Exception Reporter: |
Description
maxnitribitt
2015-12-15 15:14:47 UTC
I can add a test to ensure Models.toRaw continues to work, if that makes commenters happier. Example: User wants to register a custom binding. He tries to do it via @JSB and it fails. So I have to tell him: "You have to create a Dummy instance of a model class and call Models.toRaw(dummy) first in order to initialize knockout". I would rather like to tell him, "call Knockout.initialize(); first". If you look at the api doc of Models.toRaw, it "Converts an existing model into its associated, raw JSON object." But the user neither wants an instance of his Model, nor does he want the raw json object, he wants to initialize knockout. I know, that Models.toRaw does this as a side effect, but a clueless user who realizes that he has to initialize knockout from an error message, and looks at the API has no chance to find out how to do it. And as some smart guy put it "the primary target of an API is [...] a human" ;-) The thing is that in general it doesn't make much sense to initialize all Model technologies. What you want is to initialize knockout for java. So maybe you don't want new method in Models, but rather to make a call into KO4J directly. diff -r 5b48d93e762c -r 0ced2a7be49b client/pom.xml --- a/client/pom.xml Thu Dec 17 22:43:36 2015 +0100 +++ b/client/pom.xml Thu Dec 17 22:47:07 2015 +0100 @@ -151,7 +151,7 @@ <groupId>org.netbeans.html</groupId> <artifactId>ko4j</artifactId> <version>${net.java.html.version}</version> - <scope>runtime</scope> + <scope>compile</scope> </dependency> <dependency> <groupId>org.testng</groupId> diff -r 5b48d93e762c -r 0ced2a7be49b client/src/main/java/com/dukescript/demo/routing/DataModel.java --- a/client/src/main/java/com/dukescript/demo/routing/DataModel.java Thu Dec 17 22:43:36 2015 +0100 +++ b/client/src/main/java/com/dukescript/demo/routing/DataModel.java Thu Dec 17 22:47:07 2015 +0100 @@ -2,8 +2,8 @@ import com.dukescript.demo.routing.js.Router; import net.java.html.json.Model; -import net.java.html.json.Models; import net.java.html.json.Property; +import org.netbeans.html.ko4j.KO4J; @Model(className = "Data", targetId="", properties = { @Property (name = "page", type = String.class) @@ -15,7 +15,7 @@ */ static void onPageLoad() throws Exception { ui = new Data("#/page1"); - Models.toRaw(ui); + new KO4J().knockout().valueHasMutated(null, null); Router.registerBinding(); ui.applyBindings(); } I agree that initializing KO4J by calling valueHasMutated(null, null) isn't much better than Models.toRaw. But if you (and other reviewers) want I can add: class KO4J { /** Access to 'ko' object. Makes sure knockout.js is initialized, loaded * and its main object is accessible. * * @return JavaScript object that is usually accessible via window['ko'] */ public Object ko(); } Best solution would be automatic eager initialization for technologies that require it (like knockout). E.g. by loading them before onPageLoad. This would also be the best solution, because it would support highest level of cluelessness. "that require it" - however knockout doesn't require its initialization until applyBindings is used. Registering a custom binding requires knockout to be loaded. Registering a custom binding is a very common usecase. Registering a custom binding needs to happen before applyBindings, otherwise it's meaningless. This is the maximum I can do for HTML/Java 1.3: https://hg.netbeans.org/html4j/rev/6e836197b49e It is still slightly magical, but at least straightforward once discovered. |