2

Im building an SPA with parse.js and Vue.js and are using queries like these to pull things from my database.

  let query = new parse.Query("MyData");
  const results = await query.find();

This works fine but my data wont update automatically when there is a change to the database unless I update the page. I guess this is what livequeries are for?

I tried to subscribe but this didnt work:

  const MyClass = parse.Object.extend("MyData");
  const query = new parse.Query(MyClass);

  let subscription = await query.subscribe();
  subscription.on("open", () => {
    console.log("subscription opened");
  });

Do I misunderstand the concept of livequeries? Or can I get my data to update as soon there are updates to the database?

Any help with an approach to get my data in the frontend to update according to the changes in the database would be very much apreciated!

acroscene
  • 845
  • 4
  • 16
  • 45

1 Answers1

2

Yes. You are right. You need now to listen to the subscription events in order to get the updates:

subscription.on('create', (object) => {
  console.log('object created');
});

subscription.on('update', (object) => {
  console.log('object updated');
});

subscription.on('enter', (object) => {
  console.log('object entered');
});

subscription.on('leave', (object) => {
  console.log('object left');
});

subscription.on('leave', (object) => {
  console.log('object left');
});

I've recorded the following video while back explaining all these events: https://www.youtube.com/watch?v=bz6p9uhxx2I&t=12s

Davi Macêdo
  • 2,954
  • 1
  • 8
  • 11