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.

Bug 251075 - No way to expose callbacks through additional knockout model api.
Summary: No way to expose callbacks through additional knockout model api.
Status: RESOLVED FIXED
Alias: None
Product: web
Classification: Unclassified
Component: Knockout (show other bugs)
Version: 8.1
Hardware: PC Linux
: P2 normal (vote)
Assignee: Roman Svitanic
URL:
Keywords: API_REVIEW_FAST
Depends on: 231131
Blocks:
  Show dependency tree
 
Reported: 2015-03-10 18:18 UTC by Jaroslav Tulach
Modified: 2015-03-24 03:33 UTC (History)
2 users (show)

See Also:
Issue Type: DEFECT
Exception Reporter:


Attachments
Proposed fix (3.17 KB, patch)
2015-03-11 15:36 UTC, Roman Svitanic
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Jaroslav Tulach 2015-03-10 18:18:13 UTC
Since issue 231131 was introduced I can define properties of various types and enhance code completion in "with:", "foreach:", "text:", etc. directives. However I've just noticed that there is no way to influence "click:" - there is no way to register a function.
Comment 1 Jaroslav Tulach 2015-03-10 18:23:09 UTC
The modification of 
http://bits.netbeans.org/dev/javadoc/org-netbeans-api-knockout/overview-summary.html
the Java API is probably straight-forward. Just define new method in Bindings:

  public Bindings function(String name) {...; return this; }

which one can use to define a function:

  bindings.function("fnName");

however the question is what to generate as a resulting JavaScript? Will following be enough?

  var MyModel = {
    "fnName" : function() {},
    "int" : 10
  }

Probably something for Petr to comment on.
Comment 2 Roman Svitanic 2015-03-11 15:36:37 UTC
Created attachment 152561 [details]
Proposed fix
Comment 3 Roman Svitanic 2015-03-11 15:38:41 UTC
Please review method function(String name) in class Bindings.
Thank you.
Comment 4 Petr Pisl 2015-03-11 16:32:32 UTC
I'm not sure what exactly you are expecting in this case. If you want to have just fnName function in MyModel context, then it's ok. Probably you can also add some js doc? Like 

var MyModel = {
    /**
     * Generated by Knockout via bindings.function(.....)
     */
    "fnName" : function() {},
    "int" : 10
  }
Comment 5 Jaroslav Tulach 2015-03-12 20:41:54 UTC
The suggested change looks OK to me. Thanks for pursuing it, Roman!

Comments are in general missing in the API, one cannot assign them to primitive types neither to functions.

I guess following check would also be useful:

eng.eval("ko.value.myFunc1()")
or
assertEquals("function", eng.eval("typeof ko.value.myFunc1"));

which would guarantee myFunct1 is really a function.

> I'm not sure what exactly you are expecting in this case

I'd like to see the function in the list of offered element in "click: " binding.
Comment 6 Petr Pisl 2015-03-13 10:28:40 UTC
I have add a callback definition via Js Doc recently. It can probably helps you as well. See http://wiki.netbeans.org/NewAndNoteworthyNB81#.40callback .
Comment 7 Roman Svitanic 2015-03-19 13:55:42 UTC
If there aren't any objections, I'm going to integrate the patch (with enhanced test as  suggested in comment #5).
Comment 8 Roman Svitanic 2015-03-20 17:07:21 UTC
Changeset: 4ee2b7f5d3d3
Author:    Roman Svitanic <rsvitanic@netbeans.org>
Date:      2015-03-20 18:06
Message:   #251075: No way to expose callbacks through additional knockout model api. - fixed
Comment 9 Quality Engineering 2015-03-24 03:33:09 UTC
Integrated into 'main-silver', will be available in build *201503240001* on http://bits.netbeans.org/dev/nightly/ (upload may still be in progress)

Changeset: http://hg.netbeans.org/main-silver/rev/4ee2b7f5d3d3
User: Roman Svitanic <rsvitanic@netbeans.org>
Log: #251075: No way to expose callbacks through additional knockout model api. - fixed
Task #251075 - No way to expose callbacks through additional knockout model api.