Skip to content

Commit b78081d

Browse files
committed
gun nested fix
1 parent 6c0b01b commit b78081d

File tree

2 files changed

+28
-3
lines changed

2 files changed

+28
-3
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "@puzzle-js/client-lib",
33
"main": "dist/index.js",
4-
"version": "1.2.0",
4+
"version": "1.2.1",
55
"author": "<emre.kul@trendyol.com>",
66
"license": "MIT",
77
"repository": {

src/core.ts

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,10 +109,35 @@ export class Core extends Module {
109109
.get(key, (gunResponse: any) => {
110110
if (gunResponse.err || !gunResponse.put) {
111111
this.fetchGatewayFragment(fragment)
112-
.then(gatewayResponse => Core.gun.get(key).put(gatewayResponse));
112+
.then(gatewayResponse => Core.gun.get(key).put({
113+
...gatewayResponse,
114+
...gatewayResponse.$headers ? {
115+
$headers: JSON.stringify(gatewayResponse.$headers)
116+
} : {},
117+
...gatewayResponse.$model ? {
118+
$model: JSON.stringify(gatewayResponse.$model)
119+
} : {},
120+
}));
113121
}
114122
})
115-
.on((gunResponse: any) => this.asyncRenderResponse(fragment, gunResponse));
123+
.on((gunResponse: any) => {
124+
try {
125+
gunResponse.$model = JSON.parse(gunResponse.$model);
126+
gunResponse.$headers = JSON.parse(gunResponse.$headers);
127+
this.asyncRenderResponse(fragment, gunResponse);
128+
} catch (e) {
129+
this.fetchGatewayFragment(fragment)
130+
.then(gatewayResponse => Core.gun.get(key).put({
131+
...gatewayResponse,
132+
...gatewayResponse.$headers ? {
133+
$headers: JSON.stringify(gatewayResponse.$headers)
134+
} : {},
135+
...gatewayResponse.$model ? {
136+
$model: JSON.stringify(gatewayResponse.$model)
137+
} : {},
138+
}));
139+
}
140+
});
116141
}
117142

118143
private static fetchGatewayFragment(fragment: IPageFragmentConfig) {

0 commit comments

Comments
 (0)