canjs / can-connect

Model layer utilities for every JavaScript framework! Assemble real-time, high performance, restful data connections.
https://canjs.com/doc/can-connect.html
MIT License
29 stars 16 forks source link

localStorage should add every instance to the universal set #336

Open imaustink opened 7 years ago

imaustink commented 7 years ago

When trying to use can-connect as an interface for localStorage only, no HTTP calls, .getAll({}) results in {message: "no data", error: 404}.

This is the connection behavior I am using:

Todo.connection = connect([
  require('can-connect/data/localstorage-cache/localstorage-cache'),
  require('can-connect/constructor/constructor'),
  require('can-connect/can/map/map')
],{
  Map: Todo,
  List: Todo.List,
  name: 'todo',
  algebra: Todo.algebra
});

This branch contains my work-in-progress where I am using this behavior: https://github.com/canjs/todomvc/tree/update-canjs-example-to-3.x

cc: @justinbmeyer

nlundquist commented 7 years ago

you probably just need to include the data/callbacks & data/callbacks-cache behaviors

nlundquist commented 7 years ago

oh and localstorage-cache should be on a separate connection that is passed to the Todo.connection as the 'cacheConnection' property, e.g: https://canjs.com/doc/can-connect/data/localstorage-cache/localstorage-cache.html#Use

chasenlehara commented 7 years ago

@imaustink I assigned this to you to figure out if @nlundquist’s recommendations cover your needs, or if this is a bug that needs to be fixed.

imaustink commented 7 years ago

@chasenlehara I had a good talk with @nlundquist about this. As it stands, can-connect won't work with only localStorage. Nils explained that adding this functionality would fundamentally change how caching behaves and suggested discussing this further with @justinbmeyer to confirm this is the right plan of action. Between other priorities and the retreat, I have not been able to discuss this with Justin yet. I am hoping we'll be able to talk it over this week.

imaustink commented 7 years ago

@justinbmeyer the problem is that the localstorage behavior currently can’t return lists that weren’t calculated by some backend and then cached in it - to work as a data source it will need to be able to calculate lists itself. The question is how that should be implemented.