Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"type": "prerelease",
"comment": "Simplified C++ macros and improved their comments",
"packageName": "react-native-windows",
"email": "vmorozov@microsoft.com",
"dependentChangeType": "patch",
"date": "2020-04-10T20:52:12.369Z"
}
Original file line number Diff line number Diff line change
Expand Up @@ -573,24 +573,24 @@ void RegisterModule(ReactModuleBuilder<SimpleNativeModule2> &moduleBuilder) noex
moduleBuilder.RegisterSyncMethod(&SimpleNativeModule2::StaticAddSync, L"StaticAddSync");
moduleBuilder.RegisterSyncMethod(&SimpleNativeModule2::StaticNegateSync, L"StaticNegateSync");
moduleBuilder.RegisterSyncMethod(&SimpleNativeModule2::StaticSayHelloSync, L"StaticSayHelloSync");
moduleBuilder.RegisterConstant(&SimpleNativeModule2::Constant1, L"Constant1");
moduleBuilder.RegisterConstant(&SimpleNativeModule2::Constant2, L"const2");
moduleBuilder.RegisterConstant(&SimpleNativeModule2::Constant3, L"const3");
moduleBuilder.RegisterConstant(&SimpleNativeModule2::Constant4, L"Constant4");
moduleBuilder.RegisterConstMethod(&SimpleNativeModule2::Constant5, L"Constant5");
moduleBuilder.RegisterConstMethod(&SimpleNativeModule2::Constant6, L"Constant6");
moduleBuilder.RegisterEvent(&SimpleNativeModule2::OnIntEvent, L"OnIntEvent");
moduleBuilder.RegisterEvent(&SimpleNativeModule2::OnNoArgEvent, L"OnNoArgEvent");
moduleBuilder.RegisterEvent(&SimpleNativeModule2::OnTwoArgsEvent, L"OnTwoArgsEvent");
moduleBuilder.RegisterEvent(&SimpleNativeModule2::OnPointEvent, L"onPointEvent");
moduleBuilder.RegisterEvent(&SimpleNativeModule2::OnStringEvent, L"onStringEvent", L"MyEventEmitter");
moduleBuilder.RegisterEvent(&SimpleNativeModule2::OnJSValueEvent, L"OnJSValueEvent");
moduleBuilder.RegisterFunction(&SimpleNativeModule2::JSIntFunction, L"JSIntFunction");
moduleBuilder.RegisterFunction(&SimpleNativeModule2::JSPointFunction, L"pointFunc");
moduleBuilder.RegisterFunction(&SimpleNativeModule2::JSLineFunction, L"lineFunc");
moduleBuilder.RegisterFunction(&SimpleNativeModule2::JSNoArgFunction, L"JSNoArgFunction");
moduleBuilder.RegisterFunction(&SimpleNativeModule2::JSStringFunction, L"stringFunc", L"MyModule");
moduleBuilder.RegisterFunction(&SimpleNativeModule2::JSValueFunction, L"JSValueFunction");
moduleBuilder.RegisterConstantField(&SimpleNativeModule2::Constant1, L"Constant1");
moduleBuilder.RegisterConstantField(&SimpleNativeModule2::Constant2, L"const2");
moduleBuilder.RegisterConstantField(&SimpleNativeModule2::Constant3, L"const3");
moduleBuilder.RegisterConstantField(&SimpleNativeModule2::Constant4, L"Constant4");
moduleBuilder.RegisterConstantMethod(&SimpleNativeModule2::Constant5, L"Constant5");
moduleBuilder.RegisterConstantMethod(&SimpleNativeModule2::Constant6, L"Constant6");
moduleBuilder.RegisterEventField(&SimpleNativeModule2::OnIntEvent, L"OnIntEvent");
moduleBuilder.RegisterEventField(&SimpleNativeModule2::OnNoArgEvent, L"OnNoArgEvent");
moduleBuilder.RegisterEventField(&SimpleNativeModule2::OnTwoArgsEvent, L"OnTwoArgsEvent");
moduleBuilder.RegisterEventField(&SimpleNativeModule2::OnPointEvent, L"onPointEvent");
moduleBuilder.RegisterEventField(&SimpleNativeModule2::OnStringEvent, L"onStringEvent", L"MyEventEmitter");
moduleBuilder.RegisterEventField(&SimpleNativeModule2::OnJSValueEvent, L"OnJSValueEvent");
moduleBuilder.RegisterFunctionField(&SimpleNativeModule2::JSIntFunction, L"JSIntFunction");
moduleBuilder.RegisterFunctionField(&SimpleNativeModule2::JSPointFunction, L"pointFunc");
moduleBuilder.RegisterFunctionField(&SimpleNativeModule2::JSLineFunction, L"lineFunc");
moduleBuilder.RegisterFunctionField(&SimpleNativeModule2::JSNoArgFunction, L"JSNoArgFunction");
moduleBuilder.RegisterFunctionField(&SimpleNativeModule2::JSStringFunction, L"stringFunc", L"MyModule");
moduleBuilder.RegisterFunctionField(&SimpleNativeModule2::JSValueFunction, L"JSValueFunction");
}

TEST_CLASS (NoAttributeNativeModuleTest) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,9 @@
<ClInclude Include="$(MSBuildThisFileDirectory)JSValueTreeWriter.h" />
<ClInclude Include="$(MSBuildThisFileDirectory)JSValueWriter.h" />
<ClInclude Include="$(MSBuildThisFileDirectory)JSValueXaml.h" />
<ClInclude Include="$(MSBuildThisFileDirectory)ModuleMemberRegistration.h" />
<ClInclude Include="$(MSBuildThisFileDirectory)ModuleRegistration.h" />
<ClInclude Include="$(MSBuildThisFileDirectory)ModuleRegistry.h" />
<ClInclude Include="$(MSBuildThisFileDirectory)NativeModules.h" />
<ClInclude Include="$(MSBuildThisFileDirectory)ReactError.h" />
<ClInclude Include="$(MSBuildThisFileDirectory)ReactMemberInfo.h" />
<ClInclude Include="$(MSBuildThisFileDirectory)ReactPromise.h" />
<ClInclude Include="$(MSBuildThisFileDirectory)StructInfo.h" />
</ItemGroup>
Expand Down
75 changes: 0 additions & 75 deletions vnext/Microsoft.ReactNative.Cxx/ModuleMemberRegistration.h

This file was deleted.

41 changes: 34 additions & 7 deletions vnext/Microsoft.ReactNative.Cxx/ModuleRegistration.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,17 @@
#pragma once
#include "winrt/Microsoft.ReactNative.h"

// We implement optional parameter macros based on the StackOverflow discussion:
// https://stackoverflow.com/questions/3046889/optional-parameters-with-c-macros
// Please refer to it if you want to understand it works.
#define INTERNAL_REACT_GET_ARG_4(arg1, arg2, arg3, arg4, ...) arg4
#define INTERNAL_REACT_RECOMPOSER_4(argsWithParentheses) INTERNAL_REACT_GET_ARG_4 argsWithParentheses

//
// The macros below are internal implementation details for macro defined in nativeModules.h
//

// Register struct as a ReactNative module.
#define INTERNAL_REACT_MODULE_3_ARGS(moduleStruct, moduleName, eventEmitterName) \
struct moduleStruct; \
\
Expand All @@ -23,23 +34,39 @@
template struct moduleStruct##_ModuleRegistration<int>; \
\
template <class TRegistry> \
void RegisterModule(TRegistry &registry) noexcept { \
constexpr void RegisterModule(TRegistry &registry) noexcept { \
registry.RegisterModule( \
moduleName, eventEmitterName, winrt::Microsoft::ReactNative::ReactMemberId<__COUNTER__>{}); \
}

#define INTERNAL_REACT_MODULE_2_ARGS(moduleStruct, moduleName) \
INTERNAL_REACT_MODULE_3_ARGS(moduleStruct, moduleName, nullptr)

#define INTERNAL_REACT_MODULE_1_ARGS(moduleStruct) INTERNAL_REACT_MODULE_2_ARGS(moduleStruct, L## #moduleStruct)
#define INTERNAL_REACT_MODULE_1_ARG(moduleStruct) INTERNAL_REACT_MODULE_2_ARGS(moduleStruct, L## #moduleStruct)

#define INTERNAL_REACT_MODULE(...) \
INTERNAL_REACT_RECOMPOSER_4( \
(__VA_ARGS__, INTERNAL_REACT_MODULE_3_ARGS, INTERNAL_REACT_MODULE_2_ARGS, INTERNAL_REACT_MODULE_1_ARG, ))

// Register struct member.
// For each registered member we create a static method that registers it.
// The member Id is generated as a ReactMemberId<__COUNTER__> type.
// To invoke the static registration methods, we increment ReactMemberId while static member exists.
#define INTERNAL_REACT_MEMBER_4_ARGS(memberType, member, memberName, moduleName) \
template <class TClass, class TRegistry> \
constexpr static void RegisterMember( \
TRegistry &registry, winrt::Microsoft::ReactNative::ReactMemberId<__COUNTER__>) noexcept { \
registry.Register##memberType(&TClass::member, memberName, moduleName); \
}

#define INTERNAL_REACT_MODULE_4TH_ARG(arg1, arg2, arg3, arg4, ...) arg4
#define INTERNAL_REACT_MEMBER_3_ARGS(memberType, member, memberName) \
INTERNAL_REACT_MEMBER_4_ARGS(memberType, member, memberName, nullptr)

#define INTERNAL_REACT_MODULE_RECOMPOSER(argsWithParentheses) INTERNAL_REACT_MODULE_4TH_ARG argsWithParentheses
#define INTERNAL_REACT_MEMBER_2_ARGS(memberType, member) INTERNAL_REACT_MEMBER_3_ARGS(memberType, member, L## #member)

#define INTERNAL_REACT_MODULE(...) \
INTERNAL_REACT_MODULE_RECOMPOSER( \
(__VA_ARGS__, INTERNAL_REACT_MODULE_3_ARGS, INTERNAL_REACT_MODULE_2_ARGS, INTERNAL_REACT_MODULE_1_ARGS, ))
#define INTERNAL_REACT_MEMBER(...) \
INTERNAL_REACT_RECOMPOSER_4( \
(__VA_ARGS__, INTERNAL_REACT_MEMBER_4_ARGS, INTERNAL_REACT_MEMBER_3_ARGS, INTERNAL_REACT_MEMBER_2_ARGS, ))

namespace winrt::Microsoft::ReactNative {

Expand Down
14 changes: 0 additions & 14 deletions vnext/Microsoft.ReactNative.Cxx/ModuleRegistry.h

This file was deleted.

Loading