You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Shoebox gives you great capabilities, but using it in the real app is pretty rough. Have you ever thought that such kind of logic should be done behind the scenes? In a large codebase, defining `fastboot.isFastBoot` conditionals can be a daunting task. Furthermore, it generates a lot of boilerplate code, which obscures the solution. Sooner or later coupling with `shoebox` will spread over all routes.
416
416
417
-
Fortunately, there is an addon called [ember-data-storefront](https://embermap.github.io/ember-data-storefront/) that can help to alleviate this pain, thanks to its Fastboot mixin: https://embermap.github.io/ember-data-storefront/docs/guides/fastboot.
417
+
#### Solution: Application Adapter
418
+
419
+
One way to abstract the shoebox data storage mechanics is to move the logic into
420
+
the Application Adapter as shown below.
421
+
422
+
```
423
+
export default class ApplicationAdapter extends JSONAPIAdapter.extend(
let result = await super.findRecord(...arguments);
435
+
436
+
// must deep-copy for clean serialization.
437
+
result = JSON.parse(JSON.stringify(result));
438
+
439
+
this.fastboot.shoebox.put(key, result);
440
+
441
+
return result;
442
+
}
443
+
444
+
let result = this.fastboot.shoebox.retrieve(key);
445
+
446
+
if (!result) {
447
+
result = await super.findRecord(...arguments);
448
+
}
449
+
450
+
// must deep-copy for clean serialization.
451
+
return JSON.parse(JSON.stringify(result));
452
+
}
453
+
}
454
+
```
455
+
With this strategy, any time an ember-data `findRecord` request happens while in
456
+
Fastboot mode, the record will be put into the shoebox cache and returned. When
457
+
subsequent calls are made for that record in the hydrated application, it will
458
+
first check the shoebox data.
459
+
460
+
#### Solution: Use an Addon (ember-storefront)
461
+
462
+
Additionally, there is an addon called [ember-data-storefront](https://embermap.github.io/ember-data-storefront/) that can help to alleviate this pain, thanks to its Fastboot mixin: https://embermap.github.io/ember-data-storefront/docs/guides/fastboot.
418
463
419
464
After installing the addon and applying the mixin, your routes can look like this:
0 commit comments