Code Monkey home page Code Monkey logo

meteor-poll-and-diff-publications's Introduction

Poll-And-Diff Publications in Meteor

Suppose you have some non-reactive computation that you want to publish. For example, a complicated query from a graph database (my specific example) or the results of an REST API call to another service. In these cases, the best solution is to "poll and diff". This means recomputing based on some interval and updating the publications with what changed.

Example 1

The first example will randomly sample 5 of the players every 3 seconds (simulating polling some service), diff the results, and update the publication. You can use the ddp-analyzer-proxy to verify that the publication efficiently updates the publication.

Example 2

Now suppose you are doing some complicated query to create some feed for users. If you are scrolling through a list looking at the results, it can be kind of annoying when the order switches up on you. And expecially on mobile, you would always expect the newest results to come at the bottom, because you've already seen everything on top. This example, purposely does not stop the diff'd results and maintains the order of the results in the list. Using a template variable, we are able to preseve the order of the results until the user leaves the specific view.

Example 3 (demo)

Now suppose you have multiple services to poll-and-diff and publish to the client, but they act on the same collection. If you publish both to the same collection, the data will be mixed up. However, if you publish to different collections, then you may publish duplicate results. Thus one way to solve this problem is by adding a key to the documents that are published to the client to distinguish which collection they apply to. Luckily, merge-box will efficiently send the minimal amount of information necessary so any duplication between publications will be handled optimally.

meteor-poll-and-diff-publications's People

Contributors

ccorcos avatar

Stargazers

Grégory Horion avatar Asad Dhamani avatar Fabio Dias Rollo avatar Andrei Popovici avatar  avatar Thibault Lenclos avatar Vieko Franetovic avatar Charleno Pires avatar Babak Niknia avatar Ryen Beatty avatar Philipp Muens avatar Mickaël avatar  avatar Gopalakrishna Palem avatar

Watchers

James Cloos avatar Firdaus Ramlan avatar  avatar Devin Pastoor avatar Mickaël avatar  avatar

Forkers

sandy-slin

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.