Files
react-native/ReactCommon/fabric/core/state/StateData.h
T
Valentin Shergin 085c6d2675 Fabric: Storing data as a shared pointer inside State object
Summary:
Before this change, the concrete component-specific data/payload object associated with a State was stored inside a templated subclass as a normal instance variable; after the change, it's stored as a shared pointer inside the base class. The original motivation was that storing that inside subclass saves us one shared pointer and one heap allocation.

This approach overcomplicated a lot of things and all possible savings are probably compensated with additional complexity (we have to have templated state-update lamdas in subclasses and so on). And to update the data in the previous approach we need to create a shared pointer to data anyway.

This change will allow future improvements in the coming diff.

 Changelog: [Internal] Fabric-specific internal change.

Reviewed By: JoshuaGross

Differential Revision: D19799014

fbshipit-source-id: 287ed939353ba58d9e434d1502ecfbb208c6daa5
2020-02-09 22:28:39 -08:00

35 lines
689 B
C++

/*
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
#pragma once
#include <memory>
#ifdef ANDROID
#include <folly/dynamic.h>
#endif
namespace facebook {
namespace react {
/*
* Dummy type that is used as a placeholder for state data for nodes that
* don't have a state.
*/
struct StateData final {
using Shared = std::shared_ptr<void const>;
#ifdef ANDROID
StateData() = default;
StateData(StateData const &previousState, folly::dynamic data){};
folly::dynamic getDynamic() const;
#endif
};
} // namespace react
} // namespace facebook