Skip to content

Commit

Permalink
[core][eagle] fix event params
Browse files Browse the repository at this point in the history
  • Loading branch information
yxping committed Nov 11, 2018
1 parent d306455 commit 13a0bbb
Show file tree
Hide file tree
Showing 9 changed files with 46 additions and 41 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,4 @@ int callUpdateAttrs(String instanceId, String ref,

void resetWXBridge(boolean remoteDebug);

void fireEventOnDataRenderNode(String instanceId, String ref, String type, String data);

}
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,8 @@ static void FireEventOnDataRenderNode(JNIEnv* env, jobject jcaller,
jstring instanceId,
jstring ref,
jstring type,
jstring data);
jstring data,
jstring domChanges);

static void RegisterModuleOnDataRenderNode(JNIEnv* env, jobject jcaller,
jstring data);
Expand Down Expand Up @@ -991,6 +992,7 @@ static const JNINativeMethod kMethodsWXBridge[] = {
"Ljava/lang/String;"
"Ljava/lang/String;"
"Ljava/lang/String;"
"Ljava/lang/String;"
")"
"V", reinterpret_cast<void*>(FireEventOnDataRenderNode) },
{ "nativeRegisterModuleOnDataRenderNode",
Expand Down
13 changes: 8 additions & 5 deletions weex_core/Source/android/wrap/wx_bridge.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -582,7 +582,9 @@ static jstring ExecJSOnInstance(JNIEnv* env, jobject jcaller,
}

static void FireEventOnDataRenderNode(JNIEnv* env, jobject jcaller,
jstring instanceId, jstring ref, jstring type, jstring data) {
jstring instanceId, jstring ref,
jstring type, jstring data,
jstring domChanges) {
if (instanceId == NULL || ref == NULL || type == NULL || data == NULL) {
return;
}
Expand All @@ -591,13 +593,14 @@ static void FireEventOnDataRenderNode(JNIEnv* env, jobject jcaller,
ScopedJStringUTF8 refChar(env, ref);
ScopedJStringUTF8 typeChar(env, type);
ScopedJStringUTF8 dataChar(env, data);
ScopedJStringUTF8 domChangesChar(env, domChanges);

try {
weex::core::data_render::VNodeRenderManager::GetInstance()->FireEvent(
idChar.getChars(), refChar.getChars(), typeChar.getChars(), dataChar.getChars()
);
} catch (std::exception &e) {
auto error = static_cast<weex::core::data_render::Error *>(&e);
idChar.getChars(), refChar.getChars(), typeChar.getChars(),
dataChar.getChars(), domChangesChar.getChars());
} catch (std::exception& e) {
auto error = static_cast<weex::core::data_render::Error*>(&e);
if (error) {
LOGE("Error on FireEventOnDataRenderNode %s", error->what());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,14 @@ static const char* kKeyParams = "params";

void VNodeOnEventListener::OnEvent(VNode* node, const std::string& event,
const std::string& json_args,
const std::string dom_changes,
const VNode::Params& param_list) {
auto page_id = node->component()->exec_state()->context()->page_id();
std::vector<VALUE_WITH_TYPE*> params;
// page_id
params.push_back(Conversion::GenValueWithType(page_id.c_str()));

// args -> { method: 'fireEvent', args: [ref, event, args ,{params: [...]}] }
// args -> { method: 'fireEvent', args: [ref, "nodeEvent", args , domChanges, {params: [ {"templateId": templateId, "componentId": id, "type": type, "params" : [...]} ]}] }
VALUE_WITH_TYPE* args = getValueWithTypePtr();
args->type = ParamsType::JSONSTRING;
std::vector<json11::Json> args_object_list;
Expand All @@ -53,18 +54,33 @@ void VNodeOnEventListener::OnEvent(VNode* node, const std::string& event,
args_object.insert({kKeyMethod, kMethodFireEvent});

std::vector<json11::Json> args_in_args_object;
// nodeId
args_in_args_object.push_back(node->render_object_ref());
// event
args_in_args_object.push_back(event);
// ref TODO make sure the difference between node id and ref
args_in_args_object.push_back(node->node_id());
// type -> "nodeEvent"
args_in_args_object.push_back("nodeEvent");
// args
std::string error;
args_in_args_object.push_back(json11::Json::parse(json_args, error));
// params
// domChanges
args_in_args_object.push_back(json11::Json::parse(dom_changes, error));
// params -> [ {"templateId": templateId, "componentId": id, "type": type, "params" : [...]} ]
std::map<std::string, json11::Json> params_object;
std::vector<json11::Json> array_in_params_object;
for (auto it = param_list.begin(); it != param_list.end(); it++) {
array_in_params_object.push_back(Conversion::GenJSON(&*it));
{
std::map<std::string, json11::Json> inner_object;
// templateId
inner_object.insert({"templateId", node->component()->template_id()});
// componentId
inner_object.insert({"componentId", node->component()->id()});
// type
inner_object.insert({"type", event});
// params
std::vector<json11::Json> array_in_inner_object;
for (auto it = param_list.begin(); it != param_list.end(); it++) {
array_in_inner_object.push_back(Conversion::GenJSON(&*it));
}
inner_object.insert({kKeyParams, array_in_inner_object});
array_in_params_object.push_back(inner_object);
}
params_object.insert({kKeyParams, array_in_params_object});
args_in_args_object.push_back(params_object);
Expand Down
5 changes: 3 additions & 2 deletions weex_core/Source/core/data_render/vnode/vnode.cc
Original file line number Diff line number Diff line change
Expand Up @@ -62,14 +62,15 @@ VNode::~VNode() {
}
}

void VNode::OnEvent(const std::string &event, const std::string args) {
void VNode::OnEvent(const std::string &event, const std::string args,
const std::string dom_changes) {
if (!on_event_listener_) return;

auto it = event_params_map_->find(event);
if (it == event_params_map_->end()) return;
auto params_list = it->second;
for (auto it = params_list.begin(); it != params_list.end(); it++) {
on_event_listener_->OnEvent(this, event, args, *it);
on_event_listener_->OnEvent(this, event, args, dom_changes, *it);
}
}

Expand Down
4 changes: 3 additions & 1 deletion weex_core/Source/core/data_render/vnode/vnode.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ class VNode {
~OnEventListener() {}
virtual void OnEvent(VNode *node, const std::string &event,
const std::string &json_args,
const std::string dom_changes,
const Params &params) = 0;
};

Expand Down Expand Up @@ -102,7 +103,8 @@ class VNode {
return event_params_map_.get();
}

void OnEvent(const std::string& event, const std::string args);
void OnEvent(const std::string &event, const std::string args,
const std::string dom_changes);

inline void set_on_event_listener(std::unique_ptr<OnEventListener> listener) {
on_event_listener_ = std::move(listener);
Expand Down
21 changes: 2 additions & 19 deletions weex_core/Source/core/data_render/vnode/vnode_on_event_listener.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,24 +16,6 @@
* specific language governing permissions and limitations
* under the License.
*/
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

#ifndef CORE_DATA_RENDER_VNODE_VNODE_ON_EVENT_LISTENER_H_
#define CORE_DATA_RENDER_VNODE_VNODE_ON_EVENT_LISTENER_H_
Expand All @@ -46,7 +28,8 @@ namespace data_render {

class VNodeOnEventListener : public VNode::OnEventListener {
void OnEvent(VNode *node, const std::string &event,
const std::string &json_args, const VNode::Params &params);
const std::string &json_args, const std::string dom_changes,
const VNode::Params &params);
};

} // namespace data_render
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,7 @@ bool VNodeRenderManager::ClosePage(const std::string& page_id) {
return true;
}

void VNodeRenderManager::FireEvent(const std::string &page_id, const std::string &ref, const std::string &event,const std::string &args) {
void VNodeRenderManager::FireEvent(const std::string &page_id, const std::string &ref, const std::string &event,const std::string &args,const std::string &dom_changes) {
do {
auto iter = exec_states_.find(page_id);
if (iter == exec_states_.end()) {
Expand All @@ -382,7 +382,7 @@ void VNodeRenderManager::FireEvent(const std::string &page_id, const std::string
auto hit_test = vnode->event_params_map()->find(event);
if (hit_test != vnode->event_params_map()->end()) {
// If vnode has eat event, return.
vnode->OnEvent(event, args);
vnode->OnEvent(event, args, dom_changes);
return;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ class VNodeRenderManager {

bool RefreshPage(const std::string &page_id, const std::string &init_data);
bool ClosePage(const std::string &page_id);
void FireEvent(const std::string &page_id, const std::string &ref, const std::string &event,const std::string &args);
void FireEvent(const std::string &page_id, const std::string &ref, const std::string &event,const std::string &args,const std::string &dom_changes);
void ExecuteRegisterModules(ExecState *exec_state, std::vector<std::string>& registers);
void RegisterModules(const std::string &modules) { modules_.push_back(modules); }
void PatchVNode(ExecState *exec_state, VNode *v_node, VNode *new_node);
Expand Down

0 comments on commit 13a0bbb

Please sign in to comment.