Skip to content

hot vs cold related issue while caching requests #3

@fuunnx

Description

@fuunnx

Hi, as discussed on gitter here is the code that causes the issue :

import xs from 'xstream'
import {makeRemoteDataDriver} from 'cycle-remote-data'

const cachedDriver = () => {
  const {request} = makeRemoteDataDriver()
  const makeRequest = (path) => request({method: 'GET', url: `${HTTP_ENDPOINT}/data/${path}`})
  let cache = {}

  return {
    query(query) {
      if (cache[query]) { return cache[query] }
      return cache[query] = makeRequest(query).remember()
    }
  }
}

const repository = cachedDriver()

xs.periodic(1000).map(() => 
    repository.query('heey')
      .map(res => res.when({
        Loading: () => 'l',
        Ok: () => 'o',
        Error: () => 'e',
      }))
  )
  .flatten()
  .debug()
  .addListener({})

expected:
----l-o--o----o----o---->

got:
----l-o--l-o--l-o--l-o-->

As you said, this is a hot vs cold thing

And thanks again for the cool library btw

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions