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
3d80c2b6
Commit
3d80c2b6
authored
Sep 10, 2015
by
Adam Barth
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #1115 from abarth/no_more_disqualify
Remove "disqualified" concept
parents
829645c1
2234294d
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
81 additions
and
28 deletions
+81
-28
framework.dart
packages/flutter/lib/src/widgets/framework.dart
+15
-28
stateful_components_test.dart
packages/unit/test/widget/stateful_components_test.dart
+66
-0
No files found.
packages/flutter/lib/src/widgets/framework.dart
View file @
3d80c2b6
...
...
@@ -879,25 +879,13 @@ abstract class StatefulComponent extends Component {
StatefulComponent
({
Key
key
})
:
super
(
key:
key
);
bool
_disqualifiedFromEverAppearingAgain
=
false
;
bool
_isStateInitialized
=
false
;
void
didMount
()
{
assert
(!
_disqualifiedFromEverAppearingAgain
);
super
.
didMount
();
}
void
_buildIfDirty
()
{
assert
(!
_disqualifiedFromEverAppearingAgain
);
super
.
_buildIfDirty
();
}
bool
retainStatefulNodeIfPossible
(
StatefulComponent
newNode
)
{
assert
(!
_disqualifiedFromEverAppearingAgain
);
assert
(
newNode
!=
null
);
assert
(!
newNode
.
_isStateInitialized
);
assert
(
_canSync
(
this
,
newNode
));
assert
(
_child
!=
null
);
newNode
.
_disqualifiedFromEverAppearingAgain
=
true
;
newNode
.
_child
=
_child
;
_child
=
null
;
...
...
@@ -910,14 +898,17 @@ abstract class StatefulComponent extends Component {
// when _sync is called, our 'old' is actually the new instance that
// we are to copy state from.
void
_sync
(
Widget
old
,
dynamic
slot
)
{
assert
(!
_disqualifiedFromEverAppearingAgain
);
// TODO(ianh): _sync should only be called once when old == null
if
(
old
==
null
&&
!
_isStateInitialized
)
{
initState
()
;
_isStateInitialized
=
true
;
if
(
old
==
null
)
{
if
(!
_isStateInitialized
)
{
initState
();
_isStateInitialized
=
true
;
}
}
if
(
old
!=
null
)
if
(
old
!=
null
)
{
assert
(
_isStateInitialized
);
assert
(!
old
.
_isStateInitialized
);
syncConstructorArguments
(
old
);
}
super
.
_sync
(
old
,
slot
);
}
...
...
@@ -930,25 +921,21 @@ abstract class StatefulComponent extends Component {
// method to update `this` to account for the new values the parent
// passed to `source`. Make sure to call super.syncConstructorArguments(source)
// unless you are extending StatefulComponent directly.
// A given source can be used multiple times as a source.
// The source must not be mutated.
void
syncConstructorArguments
(
Component
source
);
Widget
syncChild
(
Widget
node
,
Widget
oldNode
,
dynamic
slot
)
{
assert
(!
_disqualifiedFromEverAppearingAgain
);
return
super
.
syncChild
(
node
,
oldNode
,
slot
);
}
// Calls function fn immediately and then schedules another build
// for this Component.
void
setState
(
void
fn
())
{
assert
(!
_disqualifiedFromEverAppearingAgain
);
fn
();
_scheduleBuild
();
}
String
toStringName
()
{
if
(
_
disqualifiedFromEverAppearingAgain
)
return
'
[[DISQUALIFIED]]
${super.toStringName()}
'
;
return
super
.
toStringName
()
;
if
(
_
isStateInitialized
)
return
'
Stateful
${super.toStringName()}
'
;
return
'Stateless
${super.toStringName()}
'
;
}
}
...
...
packages/unit/test/widget/stateful_components_test.dart
0 → 100644
View file @
3d80c2b6
import
'package:sky/animation.dart'
;
import
'package:sky/widgets.dart'
;
import
'package:test/test.dart'
;
import
'widget_tester.dart'
;
class
InnerComponent
extends
StatefulComponent
{
InnerComponent
();
bool
_didInitState
=
false
;
void
initState
()
{
_didInitState
=
true
;
}
void
syncConstructorArguments
(
InnerComponent
source
)
{
}
Widget
build
()
{
return
new
Container
();
}
}
class
OutterContainer
extends
StatefulComponent
{
OutterContainer
({
this
.
child
});
InnerComponent
child
;
void
syncConstructorArguments
(
OutterContainer
source
)
{
child
=
source
.
child
;
}
Widget
build
()
{
return
child
;
}
}
void
main
(
)
{
test
(
'resync stateful widget'
,
()
{
WidgetTester
tester
=
new
WidgetTester
();
InnerComponent
inner
;
OutterContainer
outter
;
tester
.
pumpFrame
(()
{
return
new
OutterContainer
(
child:
new
InnerComponent
());
});
tester
.
pumpFrame
(()
{
inner
=
new
InnerComponent
();
outter
=
new
OutterContainer
(
child:
inner
);
return
outter
;
});
expect
(
inner
.
_didInitState
,
isFalse
);
expect
(
inner
.
parent
,
isNull
);
outter
.
setState
(()
{});
scheduler
.
beginFrame
(
0.0
);
expect
(
inner
.
_didInitState
,
isFalse
);
expect
(
inner
.
parent
,
isNull
);
});
}
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