jsoma / tabletop

Tabletop.js gives spreadsheets legs
MIT License
3.78k stars 444 forks source link

How to use Tabletop.fetch() for refreshing data? #113

Open KokoDoko opened 8 years ago

KokoDoko commented 8 years ago

After calling Tabletop.init(url, callback); my google drive data is fetched and displayed in a html page. But at some point in the future, I need to reload the same data live, without refreshing the html page. I presumed I could call Tabletop.fetch(); to do this but it seems that Tabletop.fetch(); causes a TypeError. Do I need to call init with the url and callback again?

GeorgeStrakhov commented 8 years ago

plus one! would be very useful.

ItsJoeTurner commented 6 years ago

Did anyone figure this out?

c2troie commented 4 years ago

you can use setTimeout

WebDevJL commented 4 years ago

I did in this project.

I am currently making a npm package from the current of this repo.

timhettler commented 4 years ago

It appears that Tabletops internal Promise does not return tabletop. You must include a callback option, i.e.

function getSheetData(id) {
  return new Promise(function (resolve) {
    const options = {
      key: id,
      callback: (data, tabletop) => resolve({ data, tabletop });,
      simpleSheet: true,
    };
    Tabletop.init(options);
  });
}
timhettler commented 4 years ago

Here's a more detailed description of the issue:

If a custom callback isn't defined, it gets set to the resolve function of the Promise. (See line 173).

This issue is that Promise.resolve only accepts one argument, but the callback function is being apply-ed with two. (See line 449)

So: Tabletops callback API and the Promise API are incompatible.

I am willing to fix this issue, but the owner of this repo doesn't seem to be maintaining it anymore. Therefore, I'm providing this as forensic evidence to a future developer struggling with this issue. 🕵️