kadirahq / lokka

Simple JavaScript Client for GraphQL
MIT License
1.53k stars 61 forks source link

check diff payloads #5

Open mrphu3074 opened 8 years ago

mrphu3074 commented 8 years ago

hi,

I using lokka in client products, lokka really awesome and easier than Relay, but i have trouble about cache update. Lokka trigger my watchHandler even data not change

const query = `
  {
    posts {
      _id,
      title
    }
  }
`;
const watchHandler = (err, payload) => {
  if (err) {
    console.error(err.message);
    return;
  }

  console.log(payload);
};
const stop = client.watchQuery(query, '{}', watchHandler);

setInterval(function() {
  console.log('refetching posts');
  client.refetchQuery(query, '{}');
}, 2000);

Can we check diff payloads in func setItemPayload before update new payload and trigger callbacks?

arunoda commented 8 years ago

That's a good idea. I didn't worry about this because, in react, this is kind a okay. But I get it. For now, we can do a deep equal check here. See: https://github.com/kadirahq/lokka/blob/master/lib/cache.js#L65

We can do better, once we got the server side schema to the client. With that, we plan to use immutable JS as the core. If this is a burning issue for you, try to send me a PR.

Anyway, we'll have proper schema validations and so by February.