Hello everyone,
I’m currently learning how to develop a custom widget for Grist, and I’m wondering if anyone knows a good solution for mocking the Grist API.
So far, I’ve been deploying my web page (the Grist widget), grabbing the link, and then checking what happens directly inside Grist… which is obviously not very practical.
I suppose I could write a small JS mock like this:
if (window.self !== window.top) return; // running inside Grist, do nothing
window.grist = {
ready() {},
onRecord(fn) {
callbacks.record.push(fn);
fireCurrentRecord();
},
onRecords(fn) {
callbacks.records.push(fn);
fn(mockData.records.map(r => r.fields));
},
onOptions(fn) {
callbacks.options.push(fn);
fn({});
},
getTable() {
return {
fetchRecords: async () => mockData.records
};
},
};
I have a GitHub repository containing multiple widgets, each using different kinds of data and interacting differently with the Grist API.
So I was wondering whether someone has already thought about a clean way to organize and manage this kind of setup.

