GithubHelp home page GithubHelp logo

ember-cached-shoe's Introduction

npm npm version

ember-cached-shoe

This addon tries to improve ember-cli-fastboot rehydration process. App served by fastboot server resolves model hooks twice - in node.js environment and in the browser. This behaviour leads to making redundant requests and causes additonal slowdown after initial load.

This addon solves this problem.

Installation

ember install ember-cached-shoe

Usage

Add to your app/adapters/application.js:

import Ember        from 'ember'
import DS           from 'ember-data'
import CachedShoe   from 'ember-cached-shoe'

export default  DS.JSONAPIAdapter.extend(CachedShoe, {
  // code ommited
})

It works with any type of adapter that implements ajax function (e.g. JSONAPIAdapter, RESTAdapter). Since now, second resolvation of model hooks, will serve cached response.

app/routes/my-route.js:

import Ember from 'ember'

export default  Ember.Route.extend({
  model() {
    this.store.findAll('posts') // called twice, second call serves cached response
  }
})

How it works

It leverages capabilities of fastboot.shoebox to store results of ajax calls performed on the server. Special token is generated for each request (based on url and data). Response is stored in shoebox under that token.

ember-cached-shoe's People

Contributors

harenbroog avatar kernel-io avatar marucjmar avatar ember-tomster avatar

Stargazers

Ilya Radchenko avatar David Baker avatar Jure Cuhalev avatar Scott Newcomer avatar Adam Bedford avatar Sean Goresht avatar Greg Larrenaga avatar Bill Dami avatar Jeff Jewiss avatar Matt Gardner avatar William Weckl avatar Tony Miller avatar Onezino Moreira avatar Stephan Kaag avatar Ruslan Zavacky avatar Sergey Astapov avatar Florian Pichler avatar Chris Masters avatar Maros Hluska avatar Josh KG avatar Ryan Toronto avatar Felix Bünemann avatar Jacek Kubiak avatar Kajetan Janowski avatar Dave Laird avatar Piotr Gabryszak avatar Will Viles avatar Nick Schot avatar  avatar

Watchers

James Cloos avatar Piotr Gabryszak avatar

ember-cached-shoe's Issues

Cannot read property 'put' of undefined.

Hey, this addon seems like a great idea!

I'm unable to get it to work, ember 2.18.1 and fastboot v1.1.2 - it seems that the shoebox property is undefined in your addon's service.

I'll try and figure out why, but I thought I'd make you aware in the meantime in case I can't find a fix.

ie/edge are broken

Hello,

Please consider upgrading b2a dependency to the latest version "b2a": "1.0.11".
We got exceptions in ie/edge so I had to make a pull request to b2a. Details are here kaelzhang/b2a#3

Thank you.

Not caching some requests

I'm noticing that some requests don't get cached. It works in many simple cases with a top level route but I have a scenario where this doesn't seem to work:

  1. FastBoot runs and ember-cached-shoe caches all requests correctly.
  2. The browser finishes loading the JS and shoebox <script> tags are correctly available in the DOM
  3. Something happens, maybe a re-render by Ember that causes the script tags to disappear from the body
  4. Ember tries to make an AJAX call for some async data (maybe a has-many relationship or related data) but the shoebox script tags are now missing so the full request happens again, causing a flicker on the screen.

Have you experienced this issue? Any common workarounds? It sounds like a hack but if the shoebox data could be stored in cookies instead of DOM, it wouldn't get blown away in this scenario.

Does not work with ember-fetch

Hi,

This addon works perfectly when used with the standard ajax requests like this:

import DS from 'ember-data';
import CachedShoe from 'ember-cached-shoe';

export default DS.JSONAPIAdapter.extend(CachedShoe {
});

But not when used together with the ember-fetch adapter mixin.

import DS from 'ember-data';
import AdapterFetch from 'ember-fetch/mixins/adapter-fetch';
import CachedShoe from 'ember-cached-shoe';

export default DS.JSONAPIAdapter.extend(CachedShoe, AdapterFetch {
});

As Ember Data adopts fetch and removes jQuery is this something that should be supported?

Thanks!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.