threepointone / rakt

fast websites, by default
291 stars 12 forks source link

cache keys / idents #4

Open threepointone opened 7 years ago

threepointone commented 7 years ago

[braindump]

right now we cache data fetching(@initial) responses keyed against ƒ(modulehash, url). we should let a module define it's own cache key via an ident function (ala om next, etc). sketch -

@initial('user', /* ... */)
// or if dynamic ...
@initial(({ query }) => `user:${query.id}`, /* ... */)
class User extends Component{
  render(){
    /* ... */ 
  }
}

one issue lies with data prefetching. when we fetch data before the module loads, we have to use the default key, since we don't have a handle on the ident function yet. we'll have to do an optimistic update, rewriting once data comes in. todo.

stretch goal - right now, the babel plugin checks for decorators on classes. we should make this more generic, allowing for functional components, simple function wraps, etc