2016-05-25 02:24:57 +00:00
|
|
|
// Copyright 2004-present Facebook. All Rights Reserved.
|
|
|
|
|
2017-05-11 11:46:44 +00:00
|
|
|
#pragma once
|
2016-05-25 02:24:57 +00:00
|
|
|
|
|
|
|
#include <memory>
|
|
|
|
#include <vector>
|
|
|
|
|
2017-05-11 11:46:44 +00:00
|
|
|
#include <cxxreact/CxxModule.h>
|
|
|
|
|
2016-05-25 02:24:57 +00:00
|
|
|
namespace facebook { namespace xplat { namespace samples {
|
|
|
|
|
|
|
|
// In a less contrived example, Sample would be part of a traditional
|
|
|
|
// C++ library.
|
|
|
|
|
|
|
|
class Sample {
|
|
|
|
public:
|
|
|
|
std::string hello();
|
|
|
|
double add(double a, double b);
|
|
|
|
std::string concat(const std::string& a, const std::string& b);
|
|
|
|
std::string repeat(int count, const std::string& str);
|
|
|
|
void save(std::map<std::string, std::string> dict);
|
|
|
|
std::map<std::string, std::string> load();
|
|
|
|
void call_later(int msec, std::function<void()> f);
|
|
|
|
void except();
|
2016-08-04 18:30:01 +00:00
|
|
|
double twice(double n);
|
2016-05-25 02:24:57 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
std::map<std::string, std::string> state_;
|
|
|
|
};
|
|
|
|
|
|
|
|
class SampleCxxModule : public module::CxxModule {
|
|
|
|
public:
|
|
|
|
SampleCxxModule(std::unique_ptr<Sample> sample);
|
|
|
|
|
|
|
|
std::string getName();
|
|
|
|
|
|
|
|
virtual auto getConstants() -> std::map<std::string, folly::dynamic>;
|
|
|
|
|
|
|
|
virtual auto getMethods() -> std::vector<Method>;
|
|
|
|
|
|
|
|
private:
|
|
|
|
void save(folly::dynamic args);
|
|
|
|
void load(folly::dynamic args, Callback cb);
|
|
|
|
|
|
|
|
std::unique_ptr<Sample> sample_;
|
|
|
|
};
|
|
|
|
|
|
|
|
}}}
|
|
|
|
|
2017-05-11 11:46:44 +00:00
|
|
|
extern "C" facebook::xplat::module::CxxModule *SampleCxxModule();
|