Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dynamic API polling system #17

Open
AdamSalma opened this issue Jun 5, 2017 · 0 comments
Open

Dynamic API polling system #17

AdamSalma opened this issue Jun 5, 2017 · 0 comments
Assignees
Labels

Comments

@AdamSalma
Copy link
Owner

Create an API watcher that handles updating parts of the state dynamically, enabling a central store for external content updates.

The initial idea is something similar to the following:

// Inside redux state tree
watch: [
    {
        url: '/api/4chan/g',       // API url to monitor
        interval: 10,              // seconds to pause for
        type: BOARD_UPDATED,       // Action to use when a url returns a 200 HTTP response code
        lastRequestAt: 140374197,  // unix timestamp
        expireOnError: true        // Remove this object when a bad status code occurs, excluding 304s
    },
    { /* And so on... */}
]

The type key is used as the dynamic action type when an item is updated.

This allows for a single service to:

  • Loop over the watch items,
  • Select any that are due to be checked,
  • Check them by requesting the API url
  • If a 200 http code is returned, use the type to broadcast the response to a particular node of the redux state.

This can be efficiently implemented inside a React container that enables/disables itself when there are/aren't any items to watch.

IDEA: Add an optional normalizr schema in each object to convert the response data before dispatching it.

@AdamSalma AdamSalma self-assigned this Jun 5, 2017
@AdamSalma AdamSalma changed the title Dynamic API watcher within Redux Dynamic API polling system May 27, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant