Skip to content

Commit

Permalink
Add setMethodArgConversionSelector
Browse files Browse the repository at this point in the history
Summary: `setMethodArgConversionSelector` is method for provinding generated structs for methods' params. It was exactly how in old codegen.

Reviewed By: RSNara

Differential Revision: D16784403

fbshipit-source-id: d35bc8160be62385527299a6b8e68c1159002853
  • Loading branch information
osdnk authored and facebook-github-bot committed Aug 14, 2019
1 parent 40dd48c commit c0304aa
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ const moduleTemplate = `
Native::_MODULE_NAME_::SpecJSI::Native::_MODULE_NAME_::SpecJSI(id<RCTTurboModule> instance, std::shared_ptr<JSCallInvoker> jsInvoker)
: ObjCTurboModule("::_MODULE_NAME_::", instance, jsInvoker) {
::_PROPERTIES_MAP_::
::_PROPERTIES_MAP_::::_CONVERSION_SELECTORS_::
}`.trim();

const getterTemplate = `
Expand All @@ -48,6 +48,9 @@ const getterTemplate = `
@end
`.trim();

const argConvertionTemplate =
'\n setMethodArgConversionSelector(@"::_ARG_NAME_::", ::_ARG_NUMBER_::, @"JS_Native::_MODULE_NAME_::_Spec::_SELECTOR_NAME_:::");';

const template = `
/**
* Copyright (c) Facebook, Inc. and its affiliates.
Expand Down Expand Up @@ -221,6 +224,28 @@ module.exports = {
)
.join('\n'),
)
.replace(
'::_CONVERSION_SELECTORS_::',
properties
.map(({name: propertyName, typeAnnotation: {params}}) =>
params
.map((param, index) =>
param.typeAnnotation.type === 'ObjectTypeAnnotation' &&
param.typeAnnotation.properties
? argConvertionTemplate
.replace(
'::_SELECTOR_NAME_::',
capitalizeFirstLetter(propertyName) +
capitalizeFirstLetter(param.name),
)
.replace('::_ARG_NUMBER_::', index.toString())
.replace('::_ARG_NAME_::', propertyName)
: '',
)
.join(''),
)
.join(''),
)
.replace(/::_MODULE_NAME_::/g, name);
})
.join('\n');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ static facebook::jsi::Value __hostFunction_NativeSampleTurboModuleSpecJSI_diffic
NativeSampleTurboModuleSpecJSI::NativeSampleTurboModuleSpecJSI(id<RCTTurboModule> instance, std::shared_ptr<JSCallInvoker> jsInvoker)
: ObjCTurboModule(\\"SampleTurboModule\\", instance, jsInvoker) {
methodMap_[\\"difficult\\"] = MethodMetadata {1, __hostFunction_NativeSampleTurboModuleSpecJSI_difficult};
setMethodArgConversionSelector(@\\"difficult\\", 0, @\\"JS_NativeSampleTurboModule_SpecDifficultA:\\");
}
Expand Down

0 comments on commit c0304aa

Please sign in to comment.