Closed zhw2590582 closed 6 years ago
Hi @zhw2590582,
I think this could be a good idea, can you just be more specific and describe a use case scenario ?
Thanks, Anthodpnt
Just sometimes, every time I enter the view, I don't want to re-ajax to modify the dom. I just want to ajax once and cache the result.
common.js
import Highway from "@dogstudio/highway/build/es5/highway";
export default new Highway.Core({
renderers: {
index: () => import(/* webpackChunkName: "index" */ "./index")
}
});
index.js
import H from "./common";
export default class Renderer extends Highway.Renderer {
onEnter() {
console.log("onEnter");
}
}
// Request data once
fetchData().then(data => {
// modify the dom something...
// then update the cache
H.updateCache();
});
In my project, I don't think this is a good habit. Like:
export default class Renderer extends Highway.Renderer {
// Request data every time
onEnter() {
fetchData().then(data => {
// modify the dom every time...
});
}
}
@zhw2590582 I'm not sure to understand why you need to fetch data when entering a page.
Going to the page and then fetch data just a very common requirement. It's like getting the remote list data and rendering the table dom or something. But the remote list data doesn't change often, I don't want to request data every time I enter the page. This is just my personal advice...😄
Ok so for example you come on a page, fetch datas from an API for example to display a list or something and you want to update the cache of Highway manually. But why don't you just check if the page is in cache and fetch the datas only if it's not instead of updating the cache ?
Because Highway is just caching the dom before ajax, not the dom after ajax, I think I can handle this problem., thank you for your reply, I can close this issue now. 😄
In my project, the instance's cache can't handle ajax changes, I wonder if I should add a public method that lets the user manually update the view. Like: