Skip to content

Commit

Permalink
Fabric: Remove designated initializers in Events and Mounting (facebo…
Browse files Browse the repository at this point in the history
…ok#23441)

Summary:
This pull request removes the designated initializers in `react/mounting/**` and `react/events/**` to improve portability.

A destructor was also defined for `ShadowView` to fix this error:

```
ShadowViewMutation.cpp:14: error: undefined reference to 'facebook::react::ShadowView::~ShadowView()'
ShadowViewMutation.cpp:24: error: undefined reference to 'facebook::react::ShadowView::~ShadowView()'
clang++: error: linker command failed with exit code 1 (use -v to see invocation)
```

[General] [Changed] - Fabric: Remove designated initializers in Events and Mounting
Pull Request resolved: facebook#23441

Differential Revision: D14298890

Pulled By: shergin

fbshipit-source-id: f5d8fc6e1f5968b94e8bb3ca0c3f0e81cf892f83
  • Loading branch information
empyrical authored and facebook-github-bot committed Mar 4, 2019
1 parent a2f11cb commit cf2a289
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 19 deletions.
10 changes: 7 additions & 3 deletions ReactCommon/fabric/core/events/EventBeatBasedExecutor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,19 @@ EventBeatBasedExecutor::EventBeatBasedExecutor(

void EventBeatBasedExecutor::operator()(Routine routine, Mode mode) const {
if (mode == Mode::Asynchronous) {
execute({.routine = std::move(routine)});
execute({
/* .routine = */ std::move(routine),
});
return;
}

std::mutex mutex;
mutex.lock();

execute({.routine = std::move(routine),
.callback = [&mutex]() { mutex.unlock(); }});
execute({
/* .routine = */ std::move(routine),
/* .callback = */ [&mutex]() { mutex.unlock(); },
});

mutex.lock();
}
Expand Down
2 changes: 2 additions & 0 deletions ReactCommon/fabric/mounting/ShadowView.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ struct ShadowView final {
ShadowView() = default;
ShadowView(const ShadowView &shadowView) = default;

~ShadowView(){};

/*
* Constructs a `ShadowView` from given `ShadowNode`.
*/
Expand Down
51 changes: 35 additions & 16 deletions ReactCommon/fabric/mounting/ShadowViewMutation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,44 +11,63 @@ namespace facebook {
namespace react {

ShadowViewMutation ShadowViewMutation::CreateMutation(ShadowView shadowView) {
return ShadowViewMutation{
.type = Create, .newChildShadowView = shadowView, .index = -1};
return {
/* .type = */ Create,
/* .parentShadowView = */ {},
/* .newChildShadowView = */ shadowView,
/* .oldChildShadowView = */ {},
/* .index = */ -1,
};
}

ShadowViewMutation ShadowViewMutation::DeleteMutation(ShadowView shadowView) {
return {.type = Delete, .oldChildShadowView = shadowView, .index = -1};
return {
/* .type = */ Delete,
/* .parentShadowView = */ {},
/* .oldChildShadowView = */ shadowView,
/* .newChildShadowView = */ {},
/* .index = */ -1,
};
}

ShadowViewMutation ShadowViewMutation::InsertMutation(
ShadowView parentShadowView,
ShadowView childShadowView,
int index) {
return {.type = Insert,
.parentShadowView = parentShadowView,
.newChildShadowView = childShadowView,
.index = index};
return {
/* .type = */ Insert,
/* .parentShadowView = */ parentShadowView,
/* .oldChildShadowView = */ {},
/* .newChildShadowView = */ childShadowView,
/* .index = */ index,
};
}

ShadowViewMutation ShadowViewMutation::RemoveMutation(
ShadowView parentShadowView,
ShadowView childShadowView,
int index) {
return {.type = Remove,
.parentShadowView = parentShadowView,
.oldChildShadowView = childShadowView,
.index = index};
return {
/* .type = */ Remove,
/* .parentShadowView = */ parentShadowView,
/* .oldChildShadowView = */ childShadowView,
/* .newChildShadowView = */ {},
/* .index = */ index,
};
}

ShadowViewMutation ShadowViewMutation::UpdateMutation(
ShadowView parentShadowView,
ShadowView oldChildShadowView,
ShadowView newChildShadowView,
int index) {
return {.type = Update,
.parentShadowView = parentShadowView,
.oldChildShadowView = oldChildShadowView,
.newChildShadowView = newChildShadowView,
.index = index};
return {
/* .type = */ Update,
/* .parentShadowView = */ parentShadowView,
/* .oldChildShadowView = */ oldChildShadowView,
/* .newChildShadowView = */ newChildShadowView,
/* .index = */ index,
};
}

} // namespace react
Expand Down

0 comments on commit cf2a289

Please sign in to comment.