Skip to content

Use functions on client side outside events #140

@joaoventura

Description

@joaoventura

Suppose I want to implement a function on the client side, which is not specifically triggered by an event. Something like this:

class HellowWorldApp:
    def initialize(self, **kwargs):
        self.rdoc = kwargs['remote_document']
        self.rdoc.body.element(h1='Hello World!!!').events.add(click=self.clicked, translate=True)

    def clicked(self):
        self.heavy_clientside_computation()

    def heavy_clientside_computation(self): 
        # Do something heavy on the client's browser

So, by clicking on "Hello World" the "clicked" event is fired, but then the browser throws a JS Error because "heavy_clientside_computation(self)" was not compiled to Javascript and sent to the client..

Is there a solution for this now as the framework is?

If not, may I suggest something like a decorator so the framework knows which functions are to be sent to the client? It could be something like the following, and it could be applied to all "remote" methods, including those triggered by events (as python zen's explicit is better than implicit):

class HellowWorldApp:
    def initialize(self, **kwargs):
        self.rdoc = kwargs['remote_document']
        self.rdoc.body.element(h1='Hello World!!!').events.add(click=self.clicked, translate=True)

    @remotemethod
    def clicked(self):
        self.heavy_clientside_computation()

    @remotemethod        
    def heavy_clientside_computation(self): 
        # Do something heavy on the client's browser

In this case, all function calls inside @remotemethod's would be local browser calls, unless there was the rpc() call, which would be targeting the server.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions