Skip to content

Conversation

@buschtoens
Copy link
Contributor

@buschtoens buschtoens commented Sep 13, 2020

Crude implementation of emberjs/rfcs#656 (comment).

This allows to access the previously cached value during the recomputation of a cache.

class {
  @tracked bidders = [];

  @cached
  get bidSources() {
    const {
      // Returns cached value or `undefined` on first computation.
      bidSources: previousBidSources = [], 
      bidders
    } = this; 

    // Generate a BidSource from each bidder, but avoid doing
    // it more than once per bidder.
    return bidders.map(bidder => {
      return previousBidSources.find(prev => prev.bidder === bidder) ||
        // expensive as it downloads initial state from server
        new BidSource(bidder);
    });
  }
}

This is not intended to be merged and just for PoC'ing the idea. For this to be merged, the RFC would need to be updated.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants