Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in
Toggle navigation
F
Front-End
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
abdullh.alsoleman
Front-End
Commits
0903cb5f
Commit
0903cb5f
authored
Jan 19, 2016
by
Ian Hickson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Refactor Inherited to avoid all the tree walks during build.
parent
5494323d
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
42 additions
and
29 deletions
+42
-29
framework.dart
packages/flutter/lib/src/widgets/framework.dart
+41
-28
locale_query.dart
packages/flutter/lib/src/widgets/locale_query.dart
+1
-1
No files found.
packages/flutter/lib/src/widgets/framework.dart
View file @
0903cb5f
...
...
@@ -566,20 +566,12 @@ class _InactiveElements {
_elements
.
add
(
element
);
}
void
_reactivate
(
Element
element
)
{
assert
(
element
.
_debugLifecycleState
==
_ElementLifecycle
.
inactive
);
element
.
reactivate
();
assert
(
element
.
_debugLifecycleState
==
_ElementLifecycle
.
active
);
element
.
visitChildren
(
_reactivate
);
}
void
remove
(
Element
element
)
{
assert
(!
_locked
);
assert
(
_elements
.
contains
(
element
));
assert
(
element
.
_parent
==
null
);
_elements
.
remove
(
element
);
assert
(!
element
.
_active
);
_reactivate
(
element
);
}
}
...
...
@@ -729,6 +721,7 @@ abstract class Element<T extends Widget> implements BuildContext {
final
GlobalKey
key
=
widget
.
key
;
key
.
_register
(
this
);
}
_updateInheritance
();
assert
(()
{
_debugLifecycleState
=
_ElementLifecycle
.
active
;
return
true
;
});
}
...
...
@@ -793,7 +786,7 @@ abstract class Element<T extends Widget> implements BuildContext {
_slot
=
newSlot
;
}
Element
_
findAndActivat
eElement
(
GlobalKey
key
,
Widget
newWidget
)
{
Element
_
retakeInactiv
eElement
(
GlobalKey
key
,
Widget
newWidget
)
{
Element
element
=
key
.
_currentElement
;
if
(
element
==
null
)
return
null
;
...
...
@@ -809,13 +802,11 @@ abstract class Element<T extends Widget> implements BuildContext {
Element
_inflateWidget
(
Widget
newWidget
,
dynamic
newSlot
)
{
Key
key
=
newWidget
.
key
;
if
(
key
is
GlobalKey
)
{
Element
newChild
=
_
findAndActivat
eElement
(
key
,
newWidget
);
Element
newChild
=
_
retakeInactiv
eElement
(
key
,
newWidget
);
if
(
newChild
!=
null
)
{
assert
(
newChild
.
_parent
==
null
);
assert
(()
{
_debugCheckForCycles
(
newChild
);
return
true
;
});
newChild
.
_parent
=
this
;
newChild
.
_updateDepth
();
newChild
.
attachRenderObject
(
newSlot
);
newChild
.
activate
(
this
,
newSlot
);
Element
updatedChild
=
updateChild
(
newChild
,
newWidget
,
newSlot
);
assert
(
newChild
==
updatedChild
);
return
updatedChild
;
...
...
@@ -847,6 +838,26 @@ abstract class Element<T extends Widget> implements BuildContext {
_inactiveElements
.
add
(
child
);
// this eventually calls child.deactivate()
}
void
activate
(
Element
parent
,
dynamic
newSlot
)
{
assert
(
_debugLifecycleState
==
_ElementLifecycle
.
inactive
);
_reactivate
();
_parent
=
parent
;
_updateDepth
();
_updateInheritance
();
attachRenderObject
(
newSlot
);
assert
(
_debugLifecycleState
==
_ElementLifecycle
.
active
);
}
void
_reactivate
()
{
assert
(
_debugLifecycleState
==
_ElementLifecycle
.
inactive
);
assert
(
widget
!=
null
);
assert
(
depth
!=
null
);
assert
(!
_active
);
_active
=
true
;
assert
(()
{
_debugLifecycleState
=
_ElementLifecycle
.
active
;
return
true
;
});
visitChildren
((
Element
child
)
=>
child
.
_reactivate
());
}
void
deactivate
()
{
assert
(
_debugLifecycleState
==
_ElementLifecycle
.
active
);
assert
(
widget
!=
null
);
...
...
@@ -866,15 +877,6 @@ abstract class Element<T extends Widget> implements BuildContext {
assert
(
_debugLifecycleState
==
_ElementLifecycle
.
inactive
);
}
void
reactivate
()
{
assert
(
_debugLifecycleState
==
_ElementLifecycle
.
inactive
);
assert
(
widget
!=
null
);
assert
(
depth
!=
null
);
assert
(!
_active
);
_active
=
true
;
assert
(()
{
_debugLifecycleState
=
_ElementLifecycle
.
active
;
return
true
;
});
}
/// Called when an Element is removed from the tree permanently.
void
unmount
()
{
assert
(
_debugLifecycleState
==
_ElementLifecycle
.
inactive
);
...
...
@@ -890,22 +892,24 @@ abstract class Element<T extends Widget> implements BuildContext {
RenderObject
findRenderObject
()
=>
renderObject
;
Map
<
Type
,
InheritedElement
>
_inheritedWidgets
;
Set
<
InheritedElement
>
_dependencies
;
InheritedWidget
inheritFromWidgetOfExactType
(
Type
targetType
)
{
Element
ancestor
=
_parent
;
while
(
ancestor
!=
null
&&
ancestor
.
widget
.
runtimeType
!=
targetType
)
ancestor
=
ancestor
.
_parent
;
InheritedElement
ancestor
=
_inheritedWidgets
==
null
?
null
:
_inheritedWidgets
[
targetType
];
if
(
ancestor
!=
null
)
{
assert
(
ancestor
is
InheritedElement
);
_dependencies
??=
new
HashSet
<
InheritedElement
>();
_dependencies
.
add
(
ancestor
);
InheritedElement
typedAncestor
=
ancestor
;
typedAncestor
.
_dependants
.
add
(
this
);
ancestor
.
_dependants
.
add
(
this
);
return
ancestor
.
widget
;
}
return
null
;
}
void
_updateInheritance
()
{
_inheritedWidgets
=
_parent
?.
_inheritedWidgets
;
}
Widget
ancestorWidgetOfExactType
(
Type
targetType
)
{
Element
ancestor
=
_parent
;
while
(
ancestor
!=
null
&&
ancestor
.
widget
.
runtimeType
!=
targetType
)
...
...
@@ -1378,7 +1382,16 @@ class ParentDataElement extends _ProxyElement<ParentDataWidget> {
class
InheritedElement
extends
_ProxyElement
<
InheritedWidget
>
{
InheritedElement
(
InheritedWidget
widget
)
:
super
(
widget
);
Set
<
Element
>
_dependants
=
new
HashSet
<
Element
>();
final
Set
<
Element
>
_dependants
=
new
HashSet
<
Element
>();
void
_updateInheritance
()
{
final
Map
<
Type
,
InheritedElement
>
incomingWidgets
=
_parent
?.
_inheritedWidgets
;
if
(
incomingWidgets
!=
null
)
_inheritedWidgets
=
new
Map
<
Type
,
InheritedElement
>.
from
(
incomingWidgets
);
else
_inheritedWidgets
=
new
Map
<
Type
,
InheritedElement
>();
_inheritedWidgets
[
widget
.
runtimeType
]
=
this
;
}
void
debugDeactivated
()
{
assert
(()
{
...
...
packages/flutter/lib/src/widgets/locale_query.dart
View file @
0903cb5f
...
...
@@ -21,7 +21,7 @@ class LocaleQuery<T extends LocaleQueryData> extends InheritedWidget {
/// The data from the closest instance of this class that encloses the given context.
static
LocaleQueryData
of
(
BuildContext
context
)
{
LocaleQuery
query
=
context
.
inheritFromWidgetOfExactType
(
LocaleQuery
);
return
query
==
null
?
null
:
query
.
data
;
return
query
?
.
data
;
}
bool
updateShouldNotify
(
LocaleQuery
old
)
=>
data
!=
old
.
data
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment