Baqend / js-sdk

Baqend JavaScript SDK and CLI for High-Performance Websites
https://www.baqend.com
MIT License
26 stars 12 forks source link

No warning for weird connection state #28

Closed CapsE closed 4 years ago

CapsE commented 4 years ago

I'm using Baqend with next.js which leads to the problem that my code is run server side and client side which makes connecting to Baqend a bit of a problem because I don't have one single point in my applications lifecycle where I can connect. My solution was this piece of code

BaqendApi.connect = function() {
  return new Promise((resolve, reject) => {
    if (DB.User) {
      resolve();
    } else {
      DB.ready(resolve);
      if (!BaqendApi.connecting) {
        BaqendApi.connecting = true;
        BaqendApi.connected = true;
        console.log("Connecting to Baqend");
        DB.connect(Config.baqendApp);
      }
    }
  });
};

As you can see this function returns a promise that resolves once Baqend is connected (mostly immediately). While I was developing I forgot to call this function before doing some Baqend stuff and I could still load objects from Baqend but not update them.

DB.Page.load("/db/Page/d42c5a70-d301-41ab-bb8e-9fc47def0d4e").then(response => {
    response.route = "/test";
    response.save().then(r => {
      console.log(r);
    })
  });

This code would print the correctly updated object on the console but there was only one GET request being made. No update or save request was sent to Baqend.

let thing = new DB.Thing({type: "Test", data: data});
return thing.insert();

This code however would correctly insert the object. My ACL was set to public on everything so that was not the cause.

I'm sure this has something to do with the whole server side connection, client side connection, hot reload jimbo jambo that is going on on my end but it would still be nice to get an error of some kind if I call update and there isn't even a request being send.

CapsE commented 4 years ago

Sorry, it seems the connection was not the error.