-
Notifications
You must be signed in to change notification settings - Fork 16
/
componenteventwrapper.h
75 lines (61 loc) · 2.88 KB
/
componenteventwrapper.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
/**
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License").
* You may not use this file except in compliance with the License.
* A copy of the License is located at
*
* http://aws.amazon.com/apache2.0/
*
* or in the "license" file accompanying this file. This file 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 _APL_COMPONENT_EVENT_WRAPPER_H
#define _APL_COMPONENT_EVENT_WRAPPER_H
#include "apl/common.h"
#include "apl/primitives/objecttype.h"
namespace apl {
class ComponentEventSourceWrapper;
class ComponentEventTargetWrapper;
/**
* This class holds a weak reference to a CoreComponent and retrieves object properties that are
* exposed by the "event.source" or "event.target" bindings in data-binding contexts.
*
* All components a set of event properties as returned by CoreComponent::eventPropertyMap().
* The methods in this object retrieve those properties from the referenced Corecomponent.
*/
class ComponentEventWrapper : public ObjectData {
public:
explicit ComponentEventWrapper(const ConstCoreComponentPtr& component);
Object get(const std::string& key) const override;
Object opt(const std::string& key, const Object& def) const override;
bool has(const std::string& key) const override;
std::pair<std::string, Object> keyAt(std::size_t offset) const override;
std::uint64_t size() const override;
ConstCoreComponentPtr getComponent() const { return mComponent.lock(); }
virtual bool operator==(const ComponentEventWrapper& rhs) const = 0;
virtual bool operator==(const ComponentEventSourceWrapper& rhs) const { return false; }
virtual bool operator==(const ComponentEventTargetWrapper& rhs) const { return false; }
class ObjectType final : public MapLikeObjectType<ComponentEventWrapper> {
public:
bool truthy(const Object::DataHolder& dataHolder) const override {
return std::static_pointer_cast<ComponentEventWrapper>(dataHolder.data)->getComponent() != nullptr;
}
rapidjson::Value serialize(
const Object::DataHolder& dataHolder,
rapidjson::Document::AllocatorType& allocator) const override
{
return std::static_pointer_cast<ComponentEventWrapper>(dataHolder.data)->serialize(allocator);
}
bool equals(const Object::DataHolder& lhs, const Object::DataHolder& rhs) const override {
return *std::static_pointer_cast<ComponentEventWrapper>(lhs.data) ==
*std::static_pointer_cast<ComponentEventWrapper>(rhs.data);
}
};
protected:
std::weak_ptr<const CoreComponent> mComponent;
};
} // namespace apl
#endif // _APL_COMPONENT_EVENT_WRAPPER_H