Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(191)

Issue 9148015: Example showing alternate async measurement solution (Closed)

Created:
8 years, 11 months ago by Jacob
Modified:
8 years, 11 months ago
CC:
reviews_dartlang.org, arv (Not doing code reviews), prujohn
Visibility:
Public.

Description

Example showing alternate async measurement solution BUG= TEST= Committed: https://code.google.com/p/dart/source/detail?r=3473

Patch Set 1 : About ready for review #

Patch Set 2 : Ready for review #

Total comments: 11

Patch Set 3 : Reply to code review comments #

Total comments: 4

Patch Set 4 : Final version #

Total comments: 3
Unified diffs Side-by-side diffs Delta from patch set Stats (+983 lines, -808 lines) Patch
M client/html/release/html.dart View 1 2 10 chunks +34 lines, -21 lines 0 comments Download
M client/html/release/htmlimpl.dart View 58 chunks +250 lines, -169 lines 0 comments Download
M client/html/src/CSSStyleDeclarationWrappingImplementation.dart View 1 2 3 4 chunks +25 lines, -9 lines 0 comments Download
M client/html/src/CssClassSet.dart View 1 2 3 chunks +3 lines, -1 line 0 comments Download
M client/html/src/Document.dart View 1 3 chunks +5 lines, -5 lines 0 comments Download
M client/html/src/DocumentFragmentWrappingImplementation.dart View 1 2 4 chunks +8 lines, -13 lines 0 comments Download
M client/html/src/DocumentWrappingImplementation.dart View 1 2 3 4 chunks +12 lines, -10 lines 0 comments Download
M client/html/src/Element.dart View 1 3 chunks +7 lines, -8 lines 0 comments Download
M client/html/src/ElementWrappingImplementation.dart View 1 2 3 17 chunks +115 lines, -58 lines 0 comments Download
M client/html/src/EventTargetWrappingImplementation.dart View 1 2 chunks +2 lines, -2 lines 0 comments Download
M client/html/src/Measurement.dart View 1 3 chunks +36 lines, -67 lines 0 comments Download
M client/html/src/Node.dart View 1 2 chunks +3 lines, -1 line 0 comments Download
M client/html/src/NodeWrappingImplementation.dart View 1 2 3 9 chunks +29 lines, -3 lines 0 comments Download
M client/html/src/SVGElementWrappingImplementation.dart View 1 2 5 chunks +11 lines, -3 lines 0 comments Download
M client/html/src/TextWrappingImplementation.dart View 1 3 chunks +3 lines, -1 line 0 comments Download
M client/html/src/Window.dart View 1 2 chunks +19 lines, -7 lines 0 comments Download
M client/html/src/WindowWrappingImplementation.dart View 1 4 chunks +6 lines, -2 lines 0 comments Download
M client/layout/GridLayout.dart View 1 2 3 2 chunks +12 lines, -16 lines 0 comments Download
M client/layout/ViewLayout.dart View 1 2 8 chunks +16 lines, -18 lines 0 comments Download
M client/samples/dartcombat/views.dart View 1 6 chunks +51 lines, -41 lines 3 comments Download
M client/samples/swarm/Views.dart View 1 2 chunks +12 lines, -10 lines 0 comments Download
M client/samples/total/src/HtmlTable.dart View 1 2 chunks +2 lines, -2 lines 0 comments Download
M client/samples/total/src/InnerMenuView.dart View 1 4 chunks +17 lines, -16 lines 0 comments Download
M client/samples/total/src/SelectionManager.dart View 1 5 chunks +27 lines, -29 lines 0 comments Download
M client/samples/total/src/SpreadsheetPresenter.dart View 1 2 3 10 chunks +78 lines, -68 lines 0 comments Download
M client/tests/client/html/DocumentFragmentTests.dart View 1 12 chunks +38 lines, -41 lines 0 comments Download
M client/tests/client/html/ElementTests.dart View 1 2 3 4 chunks +6 lines, -6 lines 0 comments Download
M client/tests/client/html/MeasurementTests.dart View 1 2 chunks +11 lines, -21 lines 0 comments Download
M client/tests/client/layout/GridLayoutDemo.dart View 1 2 3 3 chunks +6 lines, -13 lines 0 comments Download
M client/tests/client/samples/swarm/swarm_tests.dart View 1 2 chunks +3 lines, -3 lines 0 comments Download
M client/tests/client/samples/total/total_test_lib.dart View 1 chunk +2 lines, -2 lines 0 comments Download
M client/touch/Scroller.dart View 1 6 chunks +17 lines, -36 lines 0 comments Download
M client/view/PagedViews.dart View 1 8 chunks +72 lines, -64 lines 0 comments Download
M client/view/SliderMenu.dart View 1 2 chunks +5 lines, -5 lines 0 comments Download
M client/view/view.dart View 1 2 3 chunks +40 lines, -37 lines 0 comments Download

Messages

Total messages: 11 (0 generated)
Jacob
Ready for initial review. I'm still writing some tests that check that the asserts fire ...
8 years, 11 months ago (2012-01-12 01:14:29 UTC) #1
Jennifer Messerly
lgtm http://codereview.chromium.org/9148015/diff/7001/client/html/src/CSSStyleDeclarationWrappingImplementation.dart File client/html/src/CSSStyleDeclarationWrappingImplementation.dart (right): http://codereview.chromium.org/9148015/diff/7001/client/html/src/CSSStyleDeclarationWrappingImplementation.dart#newcode50 client/html/src/CSSStyleDeclarationWrappingImplementation.dart:50: String get cssText() =>_ptr.cssText; space after => http://codereview.chromium.org/9148015/diff/7001/client/html/src/NodeWrappingImplementation.dart ...
8 years, 11 months ago (2012-01-13 02:19:44 UTC) #2
nweiz
lgtm In the future, will these asserts turn into something more self-documenting? It would be ...
8 years, 11 months ago (2012-01-13 02:29:53 UTC) #3
Jacob
On 2012/01/13 02:29:53, nweiz wrote: > lgtm > > In the future, will these asserts ...
8 years, 11 months ago (2012-01-17 18:53:35 UTC) #4
Jacob
http://codereview.chromium.org/9148015/diff/7001/client/html/src/CSSStyleDeclarationWrappingImplementation.dart File client/html/src/CSSStyleDeclarationWrappingImplementation.dart (right): http://codereview.chromium.org/9148015/diff/7001/client/html/src/CSSStyleDeclarationWrappingImplementation.dart#newcode50 client/html/src/CSSStyleDeclarationWrappingImplementation.dart:50: String get cssText() =>_ptr.cssText; On 2012/01/13 02:19:44, John Messerly ...
8 years, 11 months ago (2012-01-17 19:30:44 UTC) #5
arv (Not doing code reviews)
lgtm At least we tried to do the Future solution. I agree that this is ...
8 years, 11 months ago (2012-01-17 20:25:00 UTC) #6
Jacob
http://codereview.chromium.org/9148015/diff/16001/client/html/src/ElementWrappingImplementation.dart File client/html/src/ElementWrappingImplementation.dart (right): http://codereview.chromium.org/9148015/diff/16001/client/html/src/ElementWrappingImplementation.dart#newcode649 client/html/src/ElementWrappingImplementation.dart:649: // TODO(jacobr): does this dirty the layout? On 2012/01/17 ...
8 years, 11 months ago (2012-01-21 03:01:24 UTC) #7
Siggi Cherem (dart-lang)
https://chromiumcodereview.appspot.com/9148015/diff/20001/client/samples/dartcombat/views.dart File client/samples/dartcombat/views.dart (right): https://chromiumcodereview.appspot.com/9148015/diff/20001/client/samples/dartcombat/views.dart#newcode97 client/samples/dartcombat/views.dart:97: return () { overall feels good to chunk everthing ...
8 years, 11 months ago (2012-01-23 01:16:39 UTC) #8
nweiz
https://chromiumcodereview.appspot.com/9148015/diff/20001/client/samples/dartcombat/views.dart File client/samples/dartcombat/views.dart (right): https://chromiumcodereview.appspot.com/9148015/diff/20001/client/samples/dartcombat/views.dart#newcode97 client/samples/dartcombat/views.dart:97: return () { On 2012/01/23 01:16:39, sigmund wrote: > ...
8 years, 11 months ago (2012-01-24 00:23:49 UTC) #9
Jennifer Messerly
On 2012/01/24 00:23:49, nweiz wrote: > https://chromiumcodereview.appspot.com/9148015/diff/20001/client/samples/dartcombat/views.dart > File client/samples/dartcombat/views.dart (right): > > https://chromiumcodereview.appspot.com/9148015/diff/20001/client/samples/dartcombat/views.dart#newcode97 > ...
8 years, 11 months ago (2012-01-24 01:00:20 UTC) #10
Jacob
8 years, 11 months ago (2012-01-24 01:12:03 UTC) #11
If there is async support in the lamguage then using futures could be
interesting. Without it returning a Future<Future> seems too confusing for the
average developer.

On 2012/01/24 01:00:20, John Messerly wrote:
> On 2012/01/24 00:23:49, nweiz wrote:
> >
>
https://chromiumcodereview.appspot.com/9148015/diff/20001/client/samples/dart...
> > File client/samples/dartcombat/views.dart (right):
> > 
> >
>
https://chromiumcodereview.appspot.com/9148015/diff/20001/client/samples/dart...
> > client/samples/dartcombat/views.dart:97: return () {
> > On 2012/01/23 01:16:39, sigmund wrote:
> > > overall feels good to chunk everthing in phases (measure, layout, measure,
> > > layout), but syntactically, returning a callback for layout feels really
> > awkward
> > > to me.
> > > 
> > > I'm sure you guys have been debating for a while about this, so forgive me
> if
> > > you already considered something of this sort. I was trying to think if we
> can
> > > work around this awkwardness by using futures for each of these stages
> > > (measure/layout), for example:
> > > 
> > > /**
> > >  * Returns a nested future: the outer future indicates that
> > >  * the frame is ready for measurements, the inner future
> > >  * indicates that the frame is ready for for more layout,
> > >  * but no longer for measurements.
> > >  */
> > > Future<Future> window.requestMeasurementsFrame();
> > > 
> > > // Usage example
> > > final measureReady = window.requestMeasurementsFrame();
> > > measureReady.then((layoutReady) {
> > >   // ... measure
> > >   // ... measure
> > >   layoutReady.then((_) {
> > >     // ... layout
> > >     // ... layout
> > >   });
> > > };
> > > 
> > > Then, if we get await (or something similar) in the language this could be
> > > written linearly as follows:
> > > 
> > > final measureReady = window.requestMeasurementsFrame();
> > > final layoutReady = await measureReady;
> > > // ... measure
> > > // ... measure
> > > await layoutReady;
> > > // ... layout
> > > // ... layout
> > > 
> > > 
> > > So the example here would look as follows:
> > >   window.requestMeasurementFrame().then((layoutReady) {
> > >     final pos = ViewUtil.positionFromEvent(_rootNode, e);
> > >     _boatStartX = pos[0];
> > >     _boatStartY = pos[1];
> > >     layoutReady.then((_) {
> > >       // error case when the mouse was released out of the boat-placing
area
> > >       if (_moveListener != null) {
> > >          _rootNode.on.mouseMove.remove(_moveListener, false);
> > >          _possibleBoat.remove();
> > >          _moveListener = null;
> > >       }
> > >       _possibleBoat = ViewUtil.createDiv("icons boat2");
> > >       ViewUtil.placeNodeAt(_possibleBoat, _boatStartX, _boatStartY);
> > >       _rootNode.nodes.add(_possibleBoat);
> > >       _moveListener = handleMouseMove;
> > >       _rootNode.on.mouseMove.add(_moveListener);
> > >     });
> > >   });
> > > 
> > > Thoughts?
> > 
> > I like the idea of using futures. The syntax without await is a little
> awkward,
> > but no more so than the return-a-closure syntax.
> > 
> > I'd still like to see Future chaining. Here's how the example would look
using
> > Closure-style chaining:
> > 
> >   window.requestMeasurementFrame().then((layoutReady) {
> >     final pos = ViewUtil.positionFromEvent(_rootNode, e);
> >     _boatStartX = pos[0];
> >     _boatStartY = pos[1];
> >     return layoutReady;
> >   }).then((_) {
> >     // error case when the mouse was released out of the boat-placing area
> >     if (_moveListener != null) {
> >        _rootNode.on.mouseMove.remove(_moveListener, false);
> >        _possibleBoat.remove();
> >        _moveListener = null;
> >     }
> >     _possibleBoat = ViewUtil.createDiv("icons boat2");
> >     ViewUtil.placeNodeAt(_possibleBoat, _boatStartX, _boatStartY);
> >     _rootNode.nodes.add(_possibleBoat);
> >     _moveListener = handleMouseMove;
> >     _rootNode.on.mouseMove.add(_moveListener);
> >   });
> 
> The problem with the future chaining variant is layoutReady can't close over
> measured data, which makes the code worse (e.g. capturing a bunch of temporary
> data into class fields, or declaring them as variables outside of the
> requestMeasurementFrame callback ...)

Powered by Google App Engine
This is Rietveld 408576698