markdalgleish/redial

Easing migration from react-fetcher?

levity opened this issue · 1 comments

I have an app that uses the prefetch decorator, from redial's previous life as react-fetcher, thirty-plus times. I'd like to upgrade to redial for the ability to attach arbitrary lifecycle hooks even to stateless components, but I'm not looking forward to what promises to be a tedious migration... Has anyone written code to ease the migration or to continue supporting the old prefetch and defer decorators with the new version?

The migration is fairly simple, basically all you need to do is to switch the names. The main difference is rather than use defer and prefetch directly their argument just gets passed to either the fetch or defer key in the provideHooks object.

very light examples:

//before
prefetch( /* function that dispatches goes here */);
defer( /* function that dispatches goes here */);

//after
provideHooks({ 
  fetch: /* function that dispatches goes here */,
  defer: /* function that dispatches goes here */,
});

Server side / control code is also fairly simple.

//before
getDeferredData(components, obj);
//after
trigger('defer', components, obj);