浏览代码

fix promise to be async.

/main
kg 6 年前
当前提交
276cdcd8
共有 12 个文件被更改,包括 201 次插入108 次删除
  1. 4
      Assets/UIWidgets/foundation/assertions.cs
  2. 9
      Assets/UIWidgets/promise/Promise.cs
  3. 9
      Assets/UIWidgets/promise/Promise_NonGeneric.cs
  4. 1
      Assets/UIWidgets/rendering/binding.cs
  5. 36
      Assets/UIWidgets/rendering/object.cs
  6. 6
      Assets/UIWidgets/rendering/object.mixin.gen.cs
  7. 2
      Assets/UIWidgets/rendering/object.mixin.njk
  8. 16
      Assets/UIWidgets/scheduler/ticker.cs
  9. 200
      Assets/UIWidgets/widgets/binding.cs
  10. 20
      Assets/UIWidgets/widgets/framework.cs
  11. 2
      Assets/UIWidgets/widgets/gesture_detector.cs
  12. 4
      Assets/UIWidgets/widgets/scroll_position.cs

4
Assets/UIWidgets/foundation/assertions.cs


}
if (_errorCount == 0 || forceReport) {
Debug.Log(details.ToString());
Debug.LogError(details.ToString());
Debug.Log("Another exception was thrown: " + details.exceptionAsString());
Debug.LogWarning("Another exception was thrown: " + details.exceptionAsString());
}
_errorCount += 1;

9
Assets/UIWidgets/promise/Promise.cs


using System.Collections.Generic;
using System.Linq;
using RSG.Exceptions;
using UIWidgets.ui;
namespace RSG
{

{
if (CurState == PromiseState.Resolved)
{
InvokeHandler(resolveHandler, resultPromise, resolveValue);
Window.instance.scheduleMicrotask(() => {
InvokeHandler(resolveHandler, resultPromise, resolveValue);
});
InvokeHandler(rejectHandler, resultPromise, rejectionException);
Window.instance.scheduleMicrotask(() => {
InvokeHandler(rejectHandler, resultPromise, rejectionException);
});
}
else
{

9
Assets/UIWidgets/promise/Promise_NonGeneric.cs


using System.Collections.Generic;
using System.Linq;
using RSG.Exceptions;
using UIWidgets.ui;
namespace RSG
{

PendingPromises.Remove(this);
}
InvokeRejectHandlers(ex);
Window.instance.scheduleMicrotask(() => {
InvokeRejectHandlers(ex);
});
}

PendingPromises.Remove(this);
}
InvokeResolveHandlers();
Window.instance.scheduleMicrotask(() => {
InvokeResolveHandlers();
});
}

1
Assets/UIWidgets/rendering/binding.cs


public RendererBinding() {
this._pipelineOwner = new PipelineOwner(
binding: this,
onNeedVisualUpdate: this.ensureVisualUpdate
);

36
Assets/UIWidgets/rendering/object.cs


public class PipelineOwner {
public PipelineOwner(
RendererBinding binding = null,
this.binding = binding;
public readonly RendererBinding binding;
public readonly VoidCallback onNeedVisualUpdate;

bool _debugDoingLayout = false;
public void flushLayout() {
while (this._nodesNeedingLayout.Count > 0) {
var dirtyNodes = this._nodesNeedingLayout;
this._nodesNeedingLayout = new List<RenderObject>();
dirtyNodes.Sort((a, b) => a.depth - b.depth);
foreach (var node in dirtyNodes) {
if (node._needsLayout && node.owner == this) {
node._layoutWithoutResize();
D.assert(() => {
this._debugDoingLayout = true;
return true;
});
try {
while (this._nodesNeedingLayout.Count > 0) {
var dirtyNodes = this._nodesNeedingLayout;
this._nodesNeedingLayout = new List<RenderObject>();
dirtyNodes.Sort((a, b) => a.depth - b.depth);
foreach (var node in dirtyNodes) {
if (node._needsLayout && node.owner == this) {
node._layoutWithoutResize();
}
}
finally {
D.assert(() => {
this._debugDoingLayout = false;
return true;
});
}
}

public interface RenderObjectWithChildMixin {
bool debugValidateChild(RenderObject child);
RenderObject child { get; set; }
}
public interface RenderObjectWithChildMixin<ChildType> : RenderObjectWithChildMixin
where ChildType : RenderObject {
new ChildType child { get; set; }
}
public interface ContainerParentDataMixin<ChildType> where ChildType : RenderObject {

6
Assets/UIWidgets/rendering/object.mixin.gen.cs


namespace UIWidgets.rendering {
public abstract class RenderObjectWithChildMixinRenderObject<ChildType> : RenderObject, RenderObjectWithChildMixin where ChildType : RenderObject {
public abstract class RenderObjectWithChildMixinRenderObject<ChildType> : RenderObject, RenderObjectWithChildMixin<ChildType>, RenderObjectWithChildMixin where ChildType : RenderObject {
internal ChildType _child;
public ChildType child {

}
public abstract class RenderObjectWithChildMixinRenderBox<ChildType> : RenderBox, RenderObjectWithChildMixin where ChildType : RenderObject {
public abstract class RenderObjectWithChildMixinRenderBox<ChildType> : RenderBox, RenderObjectWithChildMixin<ChildType>, RenderObjectWithChildMixin where ChildType : RenderObject {
internal ChildType _child;
public ChildType child {

}
public abstract class RenderObjectWithChildMixinRenderSliver<ChildType> : RenderSliver, RenderObjectWithChildMixin where ChildType : RenderObject {
public abstract class RenderObjectWithChildMixinRenderSliver<ChildType> : RenderSliver, RenderObjectWithChildMixin<ChildType>, RenderObjectWithChildMixin where ChildType : RenderObject {
internal ChildType _child;
public ChildType child {

2
Assets/UIWidgets/rendering/object.mixin.njk


namespace UIWidgets.rendering {
{% macro RenderObjectWithChildMixin(with) %}
public abstract class RenderObjectWithChildMixin{{with}}<ChildType> : {{with}}, RenderObjectWithChildMixin where ChildType : RenderObject {
public abstract class RenderObjectWithChildMixin{{with}}<ChildType> : {{with}}, RenderObjectWithChildMixin<ChildType>, RenderObjectWithChildMixin where ChildType : RenderObject {
internal ChildType _child;
public ChildType child {

16
Assets/UIWidgets/scheduler/ticker.cs


this.debugLabel = debugLabel;
}
readonly SchedulerBinding _binding;
TickerFutureImpl _future;
public bool muted {

return false;
}
if (this._binding.framesEnabled) {
if (SchedulerBinding.instance.framesEnabled) {
if (this._binding.schedulerPhase != SchedulerPhase.idle) {
if (SchedulerBinding.instance.schedulerPhase != SchedulerPhase.idle) {
return true;
}

this.scheduleTick();
}
if (this._binding.schedulerPhase > SchedulerPhase.idle &&
this._binding.schedulerPhase < SchedulerPhase.postFrameCallbacks) {
this._startTime = this._binding.currentFrameTimeStamp;
if (SchedulerBinding.instance.schedulerPhase > SchedulerPhase.idle &&
SchedulerBinding.instance.schedulerPhase < SchedulerPhase.postFrameCallbacks) {
this._startTime = SchedulerBinding.instance.currentFrameTimeStamp;
}
return this._future;

protected void scheduleTick(bool rescheduling = false) {
D.assert(!this.scheduled);
D.assert(this.shouldScheduleTick);
this._animationId = this._binding.scheduleFrameCallback(this._tick, rescheduling: rescheduling);
this._animationId = SchedulerBinding.instance.scheduleFrameCallback(this._tick, rescheduling: rescheduling);
this._binding.cancelFrameCallbackWithId(this._animationId.Value);
SchedulerBinding.instance.cancelFrameCallbackWithId(this._animationId.Value);
this._animationId = null;
}

200
Assets/UIWidgets/widgets/binding.cs


get { return (WidgetsBinding) RendererBinding.instance; }
set { RendererBinding.instance = value; }
}
public WidgetsBinding() {
this.buildOwner.onBuildScheduled = this._handleBuildScheduled;
Window.instance.onLocaleChanged += this.handleLocaleChanged;

readonly BuildOwner _buildOwner = new BuildOwner();
public Element renderViewElement {
get { return this._renderViewElement; }
public FocusManager focusManager {
get { return this._buildOwner.focusManager; }
Element _renderViewElement;
readonly List<WidgetsBindingObserver> _observers = new List<WidgetsBindingObserver>();
public List<WidgetsBindingObserver> _observers = new List<WidgetsBindingObserver>();
public void addObserver(WidgetsBindingObserver observer) {
this._observers.Add(observer);
}
void addObserver(WidgetsBindingObserver observer) {
_observers.Add(observer);
public bool removeObserver(WidgetsBindingObserver observer) {
return this._observers.Remove(observer);
foreach (WidgetsBindingObserver observer in _observers) {
foreach (WidgetsBindingObserver observer in this._observers) {
bool removeObserver(WidgetsBindingObserver observer) {
return _observers.Remove(observer);
void handleLocaleChanged() {
// todo
// dispatchLocaleChanged(window.locale);
ensureVisualUpdate();
}
D.assert(() => {
if (this.debugBuildingDirtyElements) {
throw new UIWidgetsError(
"Build scheduled during frame.\n" +
"While the widget tree was being built, laid out, and painted, " +
"a new frame was scheduled to rebuild the widget tree. " +
"This might be because setState() was called from a layout or " +
"paint callback. " +
"If a change is needed to the widget tree, it should be applied " +
"as the tree is being built. Scheduling a change for the subsequent " +
"frame instead results in an interface that lags behind by one frame. " +
"If this was done to make your build dependent on a size measured at " +
"layout time, consider using a LayoutBuilder, CustomSingleChildLayout, " +
"or CustomMultiChildLayout. If, on the other hand, the one frame delay " +
"is the desired effect, for example because this is an " +
"animation, consider scheduling the frame in a post-frame callback " +
"using SchedulerBinding.addPostFrameCallback or " +
"using an AnimationController to trigger the animation."
);
}
void handleLocaleChanged() {
// todo
// dispatchLocaleChanged(window.locale);
return true;
});
this.ensureVisualUpdate();
protected bool debugBuildingDirtyElements = false;
if (renderViewElement != null) {
buildOwner.buildScope(renderViewElement);
D.assert(!this.debugBuildingDirtyElements);
D.assert(() => {
this.debugBuildingDirtyElements = true;
return true;
});
try {
if (this.renderViewElement != null) {
this.buildOwner.buildScope(this.renderViewElement);
}
base.drawFrame();
this.buildOwner.finalizeTree();
finally {
D.assert(() => {
this.debugBuildingDirtyElements = false;
return true;
});
}
}
base.drawFrame();
buildOwner.finalizeTree();
public RenderObjectToWidgetElement<RenderBox> renderViewElement {
get { return this._renderViewElement; }
RenderObjectToWidgetElement<RenderBox> _renderViewElement;
var _adapter = new RenderObjectToWidgetAdapter<RenderBox>(
container: renderView,
this._renderViewElement = new RenderObjectToWidgetAdapter<RenderBox>(
container: this.renderView,
debugShortDescription: "[root]",
);
_renderViewElement = _adapter.attachToRenderTree(buildOwner,
_renderViewElement as RenderObjectToWidgetElement<RenderBox>);
).attachToRenderTree(this.buildOwner, this._renderViewElement);
public RenderObjectToWidgetAdapter(Widget child, RenderObjectWithChildMixinRenderObject<T> container) : base(
new GlobalObjectKey<State<StatefulWidget>>(container)) {
public RenderObjectToWidgetAdapter(
Widget child = null,
RenderObjectWithChildMixin<T> container = null,
string debugShortDescription = null
) : base(
new GlobalObjectKey<State>(container)) {
this.debugShortDescription = debugShortDescription;
public Widget child;
public readonly Widget child;
public RenderObjectWithChildMixinRenderObject<T> container;
public readonly RenderObjectWithChildMixin<T> container;
public string debugShortDescription;
public readonly string debugShortDescription;
public override Element createElement() {
return new RenderObjectToWidgetElement<T>(this);

return container;
return (RenderObject) this.container;
public void updateRenderObject(BuildContext context, RenderObject renderObject) {
public override void updateRenderObject(BuildContext context, RenderObject renderObject) {
element = (RenderObjectToWidgetElement<T>) createElement();
element.assignOwner(owner);
owner.lockState(() => {
element = (RenderObjectToWidgetElement<T>) this.createElement();
D.assert(element != null);
element.assignOwner(owner);
});
}
else {
} else {
element._newWidget = this;
element.markNeedsBuild();
}

public override string toStringShort() {
return this.debugShortDescription ?? base.toStringShort();
}
public RenderObjectToWidgetElement(RenderObjectWidget widget) : base(widget) {
public RenderObjectToWidgetElement(RenderObjectToWidgetAdapter<T> widget) : base(widget) {
public RenderObjectToWidgetAdapter<T> widget {
public new RenderObjectToWidgetAdapter<T> widget {
get { return (RenderObjectToWidgetAdapter<T>) base.widget; }
}

public Widget _newWidget;
public new RenderObjectWithChildMixin renderObject {
get { return base.renderObject as RenderObjectWithChildMixin; }
}
if (_child != null)
visitor(_child);
if (this._child != null) {
visitor(this._child);
}
D.assert(child == _child);
_child = null;
D.assert(child == this._child);
this._child = null;
_rebuild();
this._rebuild();
D.assert(widget == newWidget);
_rebuild();
D.assert(this.widget == newWidget);
this._rebuild();
internal Widget _newWidget;
if (_newWidget != null) {
Widget newWidget = _newWidget;
_newWidget = null;
update(newWidget);
if (this._newWidget != null) {
Widget newWidget = this._newWidget;
this._newWidget = null;
this.update(newWidget);
D.assert(_newWidget == null);
D.assert(this._newWidget == null);
}
void _rebuild() {
try {
this._child = this.updateChild(this._child, this.widget.child, _rootChildSlot);
// allow
}
catch (Exception ex) {
var details = new UIWidgetsErrorDetails(
exception: ex,
library: "widgets library",
context: "attaching to the render tree"
);
UIWidgetsError.reportError(details);
Widget error = ErrorWidget.builder(details);
this._child = this.updateChild(null, error, _rootChildSlot);
}
}
public new RenderObjectWithChildMixin<T> renderObject {
get { return (RenderObjectWithChildMixin<T>) base.renderObject; }
renderObject.child = child;
D.assert(this.renderObject.debugValidateChild(child));
this.renderObject.child = (T) child;
}
protected override void moveChildRenderObject(RenderObject child, object slot) {

protected override void removeChildRenderObject(RenderObject child) {
D.assert(renderObject.child == child);
renderObject.child = null;
}
void _rebuild() {
try {
_child = updateChild(_child, widget.child, _rootChildSlot);
D.assert(_child != null);
}
catch (Exception e) {
Widget error = ErrorWidget.builder(new UIWidgetsErrorDetails(e));
_child = updateChild(null, error, _rootChildSlot);
}
D.assert(this.renderObject.child == child);
this.renderObject.child = null;
}
}
}

20
Assets/UIWidgets/widgets/framework.cs


}
internal Element _currentElement {
get { return _registry[this]; }
get {
Element result;
_registry.TryGetValue(this, out result);
return result;
}
}
public BuildContext currentContext {

public override string ToString() {
String selfType = this.GetType().ToString();
string suffix = "<State<StatefulWidget>>";
string suffix = "`1[UIWidgets.widgets.State]";
if (selfType.EndsWith(suffix)) {
selfType = selfType.Substring(0, selfType.Length - suffix.Length);
}

public virtual InheritedWidget inheritFromWidgetOfExactType(Type targetType, object aspect = null) {
D.assert(this._debugCheckStateIsActiveForAncestorLookup());
InheritedElement ancestor = this._inheritedWidgets == null ? null : this._inheritedWidgets[targetType];
InheritedElement ancestor = null;
if (this._inheritedWidgets != null) {
this._inheritedWidgets.TryGetValue(targetType, out ancestor);
}
if (ancestor != null) {
return this.inheritFromElement(ancestor, aspect: aspect);
}

public virtual InheritedElement ancestorInheritedElementForWidgetOfExactType(Type targetType) {
D.assert(this._debugCheckStateIsActiveForAncestorLookup());
InheritedElement ancestor = this._inheritedWidgets == null ? null : this._inheritedWidgets[targetType];
InheritedElement ancestor = null;
if (this._inheritedWidgets != null) {
this._inheritedWidgets.TryGetValue(targetType, out ancestor);
}
return ancestor;
}

}
ParentDataElement<RenderObjectWidget> _findAncestorParentDataElement() {
Element ancestor = _parent;
Element ancestor = this._parent;
while (ancestor != null && !(ancestor is RenderObjectElement)) {
var element = ancestor as ParentDataElement<RenderObjectWidget>;
if (element != null) {

2
Assets/UIWidgets/widgets/gesture_detector.cs


D.assert(gestures[type] != null);
D.assert(gestures[type]._debugAssertTypeMatches(type));
D.assert(!this._recognizers.ContainsKey(type));
this._recognizers[type] = oldRecognizers[type] ?? gestures[type].constructorRaw();
this._recognizers[type] = oldRecognizers.ContainsKey(type) ? oldRecognizers[type] : gestures[type].constructorRaw();
D.assert(this._recognizers[type].GetType() == type,
"GestureRecognizerFactory of type " + type + " created a GestureRecognizer of type " +
this._recognizers[type].GetType() +

4
Assets/UIWidgets/widgets/scroll_position.cs


}
base.debugFillDescription(description);
description.Add(string.Format("range: {0:F1}..{1:F1}", this.minScrollExtent, this.maxScrollExtent));
description.Add(string.Format("viewport: {0:F1}", this.viewportDimension));
description.Add(string.Format("range: {0:F1}..{1:F1}", this._minScrollExtent, this._maxScrollExtent));
description.Add(string.Format("viewport: {0:F1}", this._viewportDimension));
}
}
}
正在加载...
取消
保存