Created
December 13, 2017 20:55
-
-
Save almarklein/2c4a37a6689fd55b41aa33f8957877c7 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## Option 1 - strings for verbatim html, dicts for elements with attributes | |
class MyReactlikeWidget(ReactLike): | |
name = event.StringProp('john', settable=True) | |
def render(self): | |
return ['greet: ', | |
dict(type='b', | |
onclick=lambda:print('clicked!'), | |
innerHTML='hi ' + self.name), | |
'<br><button onclick="alert(\'told you!\')">dont click me</button>', | |
dict(type='button', | |
onclick=lambda:window.alert('told you'), | |
innerHTML='dont click me'), | |
] | |
## Option 2 - Element class to ease the spelling, second arg can be dict with args | |
class MyReactlikeWidget(ReactLike): | |
name = event.StringProp('john', settable=True) | |
def render(self): | |
return [Element('span', 'greet: '), | |
Element('b', dict(onclick=lambda:print('clicked')), | |
'hi ', | |
self.name), | |
Element('br'), | |
Element('span', '<button onclick="alert(\'told you!\')">dont click me</button>'), | |
Element('button', dict(onclick=lambda:window.alert('told you')), | |
'dont click me'), | |
] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This is awesome! I really like the second example!
Besides more structure (nesting widgets?) it would be cool to also extend the example with an input box that can be used to update
self.name
. That would complete the unidirectional feedback loop touted by react-likes.