Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7833513
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T12:44:41+00:00 2026-06-02T12:44:41+00:00

I have read the docs and looked at the source behind reactivity , but

  • 0

I have read the docs and looked at the source behind reactivity, but I don’t understand it.

Can someone explain how this works behind the scenes, as it looks like magic to me :).

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T12:44:44+00:00Added an answer on June 2, 2026 at 12:44 pm

    So it’s actually rather straight forward, at a basic level there are 2 types of functions involved:

    1. Functions that create a reactive context (reactive function)

    2. Functions that invalidate a reactive context (invalidating function)

    3. Functions that can do both. (I lied there are 3)

    When you call a reactive function it creates a context that meteor stores globally and to which the reactive function subscribes an invalidation callback. The function that you pass to a reactive function, or any functions that run from within it, can be an invalidating function and can grab the current context and store it locally. These functions can then at any time, like on a db update or simply a timer call, invalidate that context. The original reactive function would then receive that event and re-evaluate itself.

    Here’s a step by step using meteor functions (note that Tracker.autorun used to be called Deps.autorun):

    Tracker.autorun(function(){ 
      alert("Hello " + Session.get("name"));
    });
    
    Session.set("name", "Greg");
    
    1. autorun takes a function as its parameter
    2. before autorun runs this function, it creates a context
    3. autorun attaches a callback to the context‘s invalidation event
    4. This callback will re-run the function passed to autorun
    5. The function is then run in the context for the first time.
    6. Meteor stores this context globally as the currently active context
    7. Inside the function is another function: Session.get()
    8. Session.get() is both a reactive function and an invalidating function
    9. Session.get sets up it’s own context and associates it internally with the key “name”
    10. Session.get retrieves the current context (autorun’s context) globally from meteor
    11. The invalidation callback that Session.get registers to it’s own context, will simply invalidate it’s enclosing context (in this case, autorun’s context)
    12. So now we have 2 contexts, autorun’s and session.get’s
    13. when these functions return, meteor cleans up the active context global variable

    14. Session.set is another function capable of invalidating a context.

    15. in this case we’re invalidating all contexts created by Session associated with the key “name”
    16. All of those contexts, when invalidated, run their invalidation callbacks.
    17. Those callbacks just invalidate their enclosing contexts (That’s the design of Session.get and not what a invalidation callback must do)
    18. Those enclosing contexts now run their invalidation callbacks.
    19. In the autorun case, that callback runs the function we originally passed to autorun and then sets up the context again.

    The whole implementation is actually rather straight forward as well, you can see it here:
    https://github.com/meteor/meteor/blob/master/packages/tracker/tracker.js

    And a good example of how it works can be found here:
    https://github.com/meteor/meteor/blob/master/packages/reactive-dict/reactive-dict.js

    Reactive programming is not actually meteor or JS specific
    you can read about it here: http://en.wikipedia.org/wiki/Reactive_programming

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have read that you can do it, but would this really improve performance
I have read quite a lot of R docs, but I can't find anything
I have read the docs and everything but I'm very confused. I never needed
I have read all the docs I can get my hands on and google'd
I've read some docs about the .NET Garbage Collector but i still have some
I have read this question but it's not quite what I was looking for.
I have read this manual: http://git-scm.com/docs/gitignore As I am working with gitosis, I rather
I have read Oauth2 Docs but still am yet to get a start to
I have read lots of Autofac docs/wikis which indicate I can get a list
I have read through the Rails docs for Routing , Restful Resources , and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.