Skip to content

Commit

Permalink
ADD: extra props to getServicesWithMultiple
Browse files Browse the repository at this point in the history
  • Loading branch information
ahmetkuslular committed Oct 17, 2022
1 parent b19e836 commit 1c89dd4
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 15 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "voltranjs",
"version": "1.2.0-beta.0",
"version": "1.2.0-beta.6",
"main": "src/index.js",
"author": "Hepsiburada Technology Team",
"bin": {
Expand Down
20 changes: 9 additions & 11 deletions src/renderMultiple.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ function getRenderer(name, req) {
if (routeInfo) {
const urlWithPath = url.replace('/', path);
const fullComponentPath = `/components/${req.params.components ?? ''}`;

const context = {
path,
query,
Expand Down Expand Up @@ -157,17 +156,16 @@ async function setInitialStates(renderers) {

renderers.forEach(renderer => {
if (renderer.winnerMap) {
renderer.setInitialState(
reduceServicesMap(
renderer.winnerMap,
(serviceName, obj) => {
const request = renderer.winnerMap[serviceName];
obj[serviceName] = results[request.hash];
return obj;
},
{}
)
const result = reduceServicesMap(
renderer.winnerMap,
(serviceName, obj) => {
const request = renderer.winnerMap[serviceName];
obj[serviceName] = results[request.hash];
return obj;
},
{}
);
renderer.setInitialState(result);
}
});

Expand Down
6 changes: 6 additions & 0 deletions src/universal/core/apiService/utils/createApiClient.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import Request from '../../../model/Request';
import { createCacheManagerInstance } from '../../cache/cacheUtils';

const appConfig = require('__APP_CONFIG__');

function createApiClient(apiManager, middlewareFunc) {
const cacheManager = createCacheManagerInstance();

Expand Down Expand Up @@ -32,6 +34,10 @@ function createApiClient(apiManager, middlewareFunc) {
const payload = getPayload(url, method, params, configArgument);
const uri = apiManager.api.getUri(payload);

if (appConfig.dev) {
console.log(`${method.toUpperCase()}: ${apiManager.api.defaults.baseURL}${uri}`);
}

return new Request(apiManager.api, payload, uri, response);
}

Expand Down
11 changes: 10 additions & 1 deletion src/universal/model/Renderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,13 @@ export default class Renderer {
this.servicesMap = null;
this.initialState = null;
this.winnerMap = null;
this.extraProps = null;

if (
this.isPredefinedInitialStateSupported() &&
(process.env.BROWSER || (!process.env.BROWSER && !this.context.isWithoutState))
) {
this.extraProps = this.getExtraProps();
this.servicesMap = this.getServicesWithMultiple();
this.winnerMap = {};
}
Expand All @@ -32,8 +34,15 @@ export default class Renderer {
);
}

getExtraProps() {
if (this.component.object?.setExtraProps) {
return this.component.object?.setExtraProps(this.context);
}
return null;
}

getServicesWithMultiple() {
return this.component.object.getServicesWithMultiple(this.context);
return this.component.object?.getServicesWithMultiple(this.context, this.extraProps);
}

render() {
Expand Down
2 changes: 1 addition & 1 deletion src/universal/partials/Welcome/Welcome.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export default () => {
return `
<!doctype html>
<head>
<title>Welcome</title>
<title>${voltranConfig.prefix} MikroFrontend Interface</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
${welcomeStyle()}
</head>
Expand Down
2 changes: 1 addition & 1 deletion src/universal/service/getStates.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ const getStates = async (component, context, predefinedInitialState) => {
}

if (!predefinedInitialState && component?.getServerSideProps) {
initialState.data = await component.getServerSideProps(context);
initialState.data = await component.getServerSideProps(context, extraPropKeys);
}

if (initialState?.data?.subComponentFiles) {
Expand Down

0 comments on commit 1c89dd4

Please sign in to comment.