lona-web-org/lona

HTML user_data property

fscherf opened this issue · 2 comments

Sometimes i need to store extra data into my nodes and don't want to expose it in the frontend. Currently i just do node.$name = 'foo' but that feels hacky and may lead to naming conflicts in the future. I thought of a dedicated data store for user data. I am not completely sure about the name user_data though.

class MyLonaView(LonaView):
    def handle_request(self, request):
        html = HTML(
            Table(
                Tr(
                    Th('First Name'),
                    Th('Last Name'),
                )
            )
        )

        for first_name, last_name, secret_id in DATA:
            tr = Tr(
                Td(first_name),
                Td(last_name),
                events=[CLICK],
            )

            tr.user_data['secret_id'] = secret_id
            tr.handle_click = self.handle_click_on_tr

        self.show(html)

    def handle_click_on_tr(self, input_event):
        secret_id = input_event.node.user_data['secret_id']

        DATABASE.remove_user(secret_id)

@maratori, @korantu, @grigolet, @laundmo

What about server_data?

@maratori thanks for the input! I created a PR to add this feature