MCPcopy Create free account
hub / github.com/Snapchat/Valdi / apply

Method apply

valdi/src/valdi/runtime/CSS/CSSAttributesManager.cpp:27–62  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

25CSSAttributesManager::~CSSAttributesManager() = default;
26
27bool CSSAttributesManager::apply(const Value& style, const CSSAttributesManagerUpdateContext& context) {
28 if (style.isNullOrUndefined()) {
29 return removeAllStyles(context);
30 } else if (style.isArray()) {
31 SmallVector<Ref<CSSAttributes>, 2> styles;
32
33 [[maybe_unused]] size_t index = 0;
34 for (const auto& arrayItem : *style.getArray()) {
35 auto cssAttributes = castOrNull<CSSAttributes>(arrayItem.getValdiObject());
36 if (cssAttributes == nullptr) {
37 VALDI_ERROR(context.logger,
38 "Failed to apply style: Given style {} at index {} is not a CSSAttributes object",
39 style.toString(),
40 index);
41 } else {
42 styles.emplace_back(std::move(cssAttributes));
43 }
44 index++;
45 }
46
47 return setStyles(std::move(styles), context);
48 } else {
49 auto cssAttributes = castOrNull<CSSAttributes>(style.getValdiObject());
50 if (cssAttributes == nullptr) {
51 VALDI_ERROR(context.logger,
52 "Failed to apply style: Given style {} is not a CSSAttributes object",
53 style.toString());
54 return removeAllStyles(context);
55 }
56
57 SmallVector<Ref<CSSAttributes>, 2> styles;
58 styles.emplace_back(std::move(cssAttributes));
59
60 return setStyles(std::move(styles), context);
61 }
62}
63
64bool CSSAttributesManager::removeAllStyles(const CSSAttributesManagerUpdateContext& context) {
65 auto changed = false;

Callers

nothing calls this directly

Calls 5

toStringMethod · 0.65
isNullOrUndefinedMethod · 0.45
isArrayMethod · 0.45
getArrayMethod · 0.45
getValdiObjectMethod · 0.45

Tested by

no test coverage detected