Skip to content

Commit 4b4c5a2

Browse files
authored
Merge pull request #17 from adifiore/master
refactor: add get and set methods directly to lru cache
2 parents 659467f + be56e95 commit 4b4c5a2

File tree

2 files changed

+12
-8
lines changed

2 files changed

+12
-8
lines changed

SSRtest/ModifiedReact.js

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2235,13 +2235,13 @@ var ReactDOMServerRenderer = function () {
22352235
}
22362236

22372237
// IF THE CHILD HAS A CACHEKEY PROPERTY ON IT
2238-
if(child.props.cache){
2238+
if(child.props && child.props.cache){
22392239
const cacheKey = child.type.name + JSON.stringify(child.props);
2240-
if (!cache.storage.get(cacheKey)){
2240+
if (!cache.get(cacheKey)){
22412241
start[cacheKey] = out.length;
22422242
out += this.render(child, frame.context, frame.domNamespace);
22432243
} else {
2244-
out += cache.storage.get(cacheKey);
2244+
out += cache.get(cacheKey);
22452245
}
22462246
} else {
22472247
out += this.render(child, frame.context, frame.domNamespace);
@@ -2270,7 +2270,7 @@ var ReactDOMServerRenderer = function () {
22702270
} while (tagStack.length !== 0);
22712271

22722272
// cache component by slicing 'out'
2273-
cache.storage.set(component, out.slice(start[component], tagEnd));
2273+
cache.set(component, out.slice(start[component], tagEnd));
22742274
}
22752275
return out;
22762276
};
@@ -2613,9 +2613,16 @@ class ComponentCache {
26132613
length: (n, key) => {
26142614
return n.length + key.length;
26152615
}
2616-
});
2616+
});
2617+
}
2618+
get(cacheKey, cb) {
2619+
return this.storage.get(cacheKey);
2620+
}
26172621

2622+
set(cacheKey, html) {
2623+
this.storage.set(cacheKey, html);
26182624
}
2625+
26192626
}
26202627

26212628
// Note: when changing this, also consider https://github.com/facebook/react/issues/11526

SSRtest/src/shared/List.js

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,6 @@ export default class List extends Component {
1616
<div>
1717
<h1>Here's my list</h1>
1818
{bunchOfPics}
19-
{/* <ListItem />
20-
<ListItem />
21-
<ListItem /> */}
2219
</div>
2320
);
2421
}

0 commit comments

Comments
 (0)