3 ms·
Dart's html library used to make all methods that cause layout, be asynchronous. Instead of Element.offsetHeight, you had Element.offset which returned a Future
by spankalee 11y ago
Dart's html library used to make all methods that cause layout, be asynchronous. Instead of Element.offsetHeight, you had Element.offset which returned a Future<Rect> (Promise in JS). Code ended up looking like:
fooify(element) {
element.offset().then((rect) {
// do stuff
otherelement.offset().then((rect) {
// do more stuff
});
});
}
Understandably, developers didn't like it, and unfortunately it was removed. This was before Futures and Streams had been made completely ubiquitous in Dart, and before async/await. Now the code would look like:
fooify(element) async {
var h = await element.offsetHeight;
// do stuff
var h2 = await otherelement.offsetHeight;
// do more stuff
}
which is much more palatable.
> There'd also been talk of doing a subset of HTML that includes only the operations that can be done quickly, but to my knowledge, that never went anywhere. You run into problems with the whole huge installed base of the web; if you're going to throw everything out and start from scratch, why not just use a native mobile app, or even raw OpenGL ES commands?
Interestingly, this was basically the origin of Flutter. It started as a fork of Blink with the worst things removed, but still used DOM and JS, but they kept removing and removing, eventually removing CSS and the DOM entirely, and replacing JavaScript with Dart. Now things are fast, but they aren't like the web either.