Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding AutobahnJS definition #3956

Merged
merged 1 commit into from Mar 29, 2015
Merged

Adding AutobahnJS definition #3956

merged 1 commit into from Mar 29, 2015

Conversation

darkl
Copy link
Contributor

@darkl darkl commented Mar 24, 2015

Type definitions for AutobahnJS.

vvakame added a commit that referenced this issue Mar 29, 2015
Adding AutobahnJS definition
@vvakame vvakame merged commit eb1de10 into DefinitelyTyped:master Mar 29, 2015
1 check passed
@vvakame
Copy link
Member

@vvakame vvakame commented Mar 29, 2015

@darkl thanks mate!

bradws
Copy link

@bradws bradws commented on c7cb3bc Jun 13, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think there is a problem with the test here in file autobahn-tests.ts

The method add2(...) seems to be unable to reference the variable add2Count.

i.e. you can't do:

    add2(args: Array<number>): number {
        //return args[0] + args[1];                     // This works just fine
        return args[0] + args[1] + this.add2Count;      // This returns 'null' because it cant see 'this.add2Count'
    }

In a normal Typescript function call like the one above, the function is able to reference the this.add2Count variable when calling the add2(...) function. However since this particular function is being 'registered' with Autobahn, when the function executes, it can't (for some reason-is it a Typescript or Autobahn thing?) see anything 'outside' the function.

Is it possible to allow registered Autobahn/WAMP functions to reference variables outside the function yet inside a class like this - is there a particular pattern one can use? Can you provide a test like this?

darkl
Copy link
Contributor Author

@darkl darkl commented on c7cb3bc Jun 13, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bradws you are right that this is not bound. Replace registration line with this line:

        // 3) register a procedure for remoting
        session.register('com.myapp.add2', myInstance.add2.bind(myInstance));

bradws
Copy link

@bradws bradws commented on c7cb3bc Jun 13, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@darkl Oh that's working now thanks! What is this 'bind' method - javascript/typescript/autobahn ??

darkl
Copy link
Contributor Author

@darkl darkl commented on c7cb3bc Jun 13, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bradws, Javascript method. Binds the method with this argument and (optionally) with other method arguments (so you don't have to specify them every call).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants