The Session

Παράρτημα 5.5

Μεταφρασμένο Ποσοστό

Σε αυτό το κεφάλαιο θα:

  • Learn about the Meteor Session
  • Learn about the autorun function
  • Learn about Hot Code Reload
  • ////

    ////

    ////

    The Meteor Session

    ////

    ////

    ////

    Changing the Session

    ////

     Session.set('pageTitle', 'A different title');
    
    Browser console

    ////

    ////

    <header class="navbar navbar-default" role="navigation"> 
      <div class="navbar-header">
        <a class="navbar-brand" href="{{pathFor 'postsList'}}">{{pageTitle}}</a>
      </div>
    </header>
    
    client/templates/application/layout.html
    Template.layout.helpers({
      pageTitle: function() { return Session.get('pageTitle'); }
    });
    
    client/templates/application/layout.js

    A Note About Sidebar Code

    ////

    ////

    ////

     Session.set('pageTitle', 'A brand new title');
    
    Browser console

    ////

    ////

    Identical Changes

    ////

    Introducing Autorun

    ////

    ////

    helloWorld = function() {
      alert(Session.get('message'));
    }
    

    ////

    ////

    ////

     Tracker.autorun( function() { console.log('Value is: ' + Session.get('pageTitle')); } );
    Value is: A brand new title
    
    Browser console

    ////

     Session.set('pageTitle', 'Yet another value');
    Value is: Yet another value
    
    Browser console

    ////

    ////

    Tracker.autorun(function() {
      alert(Session.get('message'));
    });
    

    ////

    Hot Code Reload

    ////

    ////

    ////

     Session.set('pageTitle', 'A brand new title');
     Session.get('pageTitle');
    'A brand new title'
    
    Browser console

    ////

     Session.get('pageTitle');
    'A brand new title'
    
    Browser console

    ////

    ////

    ////

     Session.get('pageTitle');
    null
    
    Browser console

    ////

    ////

    //// ////

    ////