mirror of
https://github.com/aspnet/JavaScriptServices.git
synced 2025-12-22 17:47:53 +00:00
Simplify ReactRenderer API when referencing default modules
This commit is contained in:
@@ -27,7 +27,7 @@ module.exports = {
|
||||
renderToString: function(callback, options) {
|
||||
var resolvedPath = path.resolve(process.cwd(), options.moduleName);
|
||||
var requestedModule = require(resolvedPath);
|
||||
var component = requestedModule[options.exportName];
|
||||
var component = options.exportName ? requestedModule[options.exportName] : requestedModule;
|
||||
if (!component) {
|
||||
throw new Error('The module "' + resolvedPath + '" has no export named "' + options.exportName + '"');
|
||||
}
|
||||
|
||||
@@ -12,6 +12,10 @@ namespace Microsoft.AspNet.NodeServices.React
|
||||
nodeScript = new StringAsTempFile(script); // Will be cleaned up on process exit
|
||||
}
|
||||
|
||||
public static Task<string> RenderToString(INodeServices nodeServices, string moduleName, string baseUrl) {
|
||||
return RenderToString(nodeServices, moduleName, /* exportName */ null, baseUrl);
|
||||
}
|
||||
|
||||
public static async Task<string> RenderToString(INodeServices nodeServices, string moduleName, string exportName, string baseUrl) {
|
||||
return await nodeServices.InvokeExport(nodeScript.FileName, "renderToString", new {
|
||||
moduleName,
|
||||
|
||||
Reference in New Issue
Block a user