Skip to content
This repository was archived by the owner on Jun 3, 2021. It is now read-only.

Commit cf9f457

Browse files
committed
[core] fix event error
1 parent 1866fe9 commit cf9f457

File tree

1 file changed

+16
-12
lines changed

1 file changed

+16
-12
lines changed

weex_core/Source/core/data_render/vnode/vnode_render_manager.cc

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -868,24 +868,26 @@ void CompareAndApplyEvents1(const std::string& page_id, VNode* old_node,
868868
VNode* new_node) {
869869
std::map<std::string, void*> old_events = *old_node->events();
870870
std::map<std::string, void*> new_events = *new_node->events();
871+
std::map<std::string, void*> remove_events;
872+
std::map<std::string, void*> add_events;
871873

872874
for (auto it = old_events.cbegin(); it != old_events.cend(); it++) {
873875
auto pos = new_events.find(it->first);
874-
if (pos != new_events.end()) {
875-
new_events.erase(pos);
876+
if (pos == new_events.end()) {
877+
remove_events.insert(*it);
876878
}
877879
}
878880
for (auto it = new_events.cbegin(); it != new_events.cend(); it++) {
879881
auto pos = old_events.find(it->first);
880-
if (pos != old_events.end()) {
881-
old_events.erase(pos);
882+
if (pos == old_events.end()) {
883+
add_events.insert(*it);
882884
}
883885
}
884-
for (auto it = old_events.cbegin(); it != old_events.cend(); it++) {
886+
for (auto it = remove_events.cbegin(); it != remove_events.cend(); it++) {
885887
RenderManager::GetInstance()->RemoveEvent(
886888
page_id, new_node->render_object_ref(), it->first);
887889
}
888-
for (auto it = new_events.cbegin(); it != new_events.cend(); it++) {
890+
for (auto it = add_events.cbegin(); it != add_events.cend(); it++) {
889891
RenderManager::GetInstance()->AddEvent(
890892
page_id, new_node->render_object_ref(), it->first);
891893
}
@@ -896,25 +898,27 @@ void CompareAndApplyEvents2(const std::string& page_id, VNode* old_node,
896898
VNode::EventParamsMap old_events = *old_node->event_params_map();
897899
VNode::EventParamsMap new_events = *new_node->event_params_map();
898900

901+
VNode::EventParamsMap remove_events;
902+
VNode::EventParamsMap add_events;
899903
for (auto it = old_events.cbegin(); it != old_events.cend(); it++) {
900904
auto pos = new_events.find(it->first);
901905

902-
if (pos != new_events.end()) {
903-
new_events.erase(pos);
906+
if (pos == new_events.end()) {
907+
remove_events.insert(*it);
904908
}
905909
}
906910
for (auto it = new_events.cbegin(); it != new_events.cend(); it++) {
907911
auto pos = old_events.find(it->first);
908912

909-
if (pos != old_events.end()) {
910-
old_events.erase(pos);
913+
if (pos == old_events.end()) {
914+
add_events.insert(*it);
911915
}
912916
}
913-
for (auto it = old_events.cbegin(); it != old_events.cend(); it++) {
917+
for (auto it = remove_events.cbegin(); it != remove_events.cend(); it++) {
914918
RenderManager::GetInstance()->RemoveEvent(
915919
page_id, new_node->render_object_ref(), it->first);
916920
}
917-
for (auto it = new_events.cbegin(); it != new_events.cend(); it++) {
921+
for (auto it = add_events.cbegin(); it != add_events.cend(); it++) {
918922
RenderManager::GetInstance()->AddEvent(
919923
page_id, new_node->render_object_ref(), it->first);
920924
}

0 commit comments

Comments
 (0)