Quiz

  1. Can you go over the significance of why we do export { LocalStore }; or export { DataStore };

    Sure. This is our module interface. The module gets to decide what name(s) are exported (and can be imported). Something that isn't exported is completely private. (Unlike, say, Python, where importing a module gets you access to all the names.)

    In the main-module, there's a matching import statement. Let's look at that. main-module.js

    It's also possible to rename while importing, so a module can

    
    export { someVeryLongDescriptiveName }
    
    

    and the importing module can:

    
    import { short } from ./module.js
    
    
  2. I would like to discuss more about the adjustments that were made in Main.

    Sure. Let's talk about them again. The highlights:

    • load from local storage
    • If there were saved order, reconstruct the checklist
  3. Does this mean values from other projects uploaded to Heroku might be accidentally accessed because the projects share the origin? Wouldn't this be an exploitable vulnerability?

    Yes! I remember seeing "coffee orders" that had been saved from other users.

    I also remember long ago having an app that allowed students to insert "comments" and I later discovered it being used as a chat channel by some non-Wellesley people!

  4. Could you explain the difference between .get and .getItem?

    Glad to. .get is the name chosen by the CoffeeRun designers for a method that gets data from a data store. The LocalStore has the same method, but it gets the data from the browser's local storage feature.

    .getItem is a method for the browser-based feature.

    There are layers here. I'll draw a picture.

  5. Could you also explain this function in detail? I don't quite understand why we only need to access the keys and not t he values:
        
        function showDictionary(dic) {
            let keys = Object.keys(dic);
            keys.map(k => console.log(k, '=>', dic[k]));
        }
    

    It does access the values! That's what dic[k] does. The console.log prints both the key and the value. You could do the following instead:

    
        function showDictionary(dic) {
            let keys = Object.keys(dic);
            keys.forEach( key => {
                const val = dic[key]; 
                console.log(key, '=>', val); 
            });
        }
    
    

    The original function really should use forEach and not map. That's an error.