mariposa-dart / mariposa

React-esque Web application framework for Dart. Supports SSR and more.
https://pub.dartlang.org/packages/mariposa
MIT License
20 stars 0 forks source link

Elements should be isomorphic #3

Closed thosakwe closed 7 years ago

thosakwe commented 7 years ago

Have a custom renderer for browser and io

thosakwe commented 7 years ago

For this to work, there needs to be some sort of isomorphic dom wrapper library.

thosakwe commented 7 years ago

Something like this would be nice, and make it easy to close event subscriptions...

abstract class AbstractElement {
  Iterable<AbstractElement> get children;

  AbstractElement get parent;

  AbstractElement querySelector(String query);

  Iterable<AbstractElement> querySelectorAll(String query);

  void listen<T>(String eventName, void callback(T event));

  Future close();
}

import 'dart:html' as html;

class CheckboxWidget extends Widget<bool> {
  @override
  void afterRender(AbstractElement $el, State<bool> state) {
    $el.listen<html.Event>('click', (html.Event e) {
        state.set('value', !state['value']);
     });
  }

  @override
  Node render(State<bool> state) {
    return input(type: 'checkbox', checked: state['value']);
  }
}