I'm writing a single page application using mithril. The page loads some data from the server using m.request() in the oninit of the main component:
var root = document.getElementById("main");
var Data = {
fetch: function () {
m.request({
method: "GET",
url: "/api/read"
})
.then(function (items) {
// init models with data
});
}
}
var Home = {
oninit: Data.fetch,
view: function (vnode) {
return m("div", [components]);
}
}
m.route(root,
"/",
{
"/": Home
});
The data is a huge json, the page is to help edit the json by ensuring that certain foreign key constraints are met, and visualising it a bit better. Everything works as expected until a call a component that actually adds a brand new entry to any of the json objects i have. At this stage the page reloads, and the data gets fetched again, so I lose all the changes. It only ever happens once though and only on this call:
jsonModel[propertyName].push(JSON.parse(newObject))
After this first redraw I can modify the page as much as I like, this issue will not happen again. I can even refresh without it occurring.
Am I doing something fundamentally wrong in my structure? Can this refresh be prevented?