Git Product home page Git Product logo

Comments (5)

matt-kruse avatar matt-kruse commented on May 27, 2024

request.session(key) will return the session value, and response.session(key,value) will set a new one. You can still get to the sessionAttributes directly, but I find those utility methods to be more straight-forward.

from alexa-app.

OverloadUT avatar OverloadUT commented on May 27, 2024

But that still means it's impossible to get the current sessionsAttributes staged in the response via your utility method. At the very least response.session(key) should get the current value.

In javascript and especially node I'm not used to seeing getter and setter methods for no reason. Typically an object is just exposed and the user uses that directly. I only see downsides of this method, such as losing out on all operators. Consider the semantic readability of this (this would assume you would make response.session a getter as well):

// Using methods
response.session('totalScore', response.session('totalScore') + response.session('roundScore'));

// Using the object
response.session.totalScore += response.session.roundScore;

It's not huge yeah, but the latter is what you see everywhere in Javascript. By forcing the use of methods to set a variable, you lose out on all of the operators. For example, you can't delete a parameter from the object right now. You can either set it to null (which is not the same as non-existent, and will actually get put in to the JSON string) or set it as undefined which is also, paradoxically, not the same as actually having it undefined. Javascript is kind of lame like that.

At the end of the day it's not a big deal so long as you leave response.response.sessionAttributes available to manipulate directly; I'm just trying to give feedback on making this thing a rock solid module that follows as close to node module standards (let's be honest and use that term very loosely ;) )

from alexa-app.

matt-kruse avatar matt-kruse commented on May 27, 2024

Like you said, everything is still exposed. The session methods are just shortcuts for common operations. In 2.1 I've added a response.clearSession() function, which either clears all response session data, or if passed a key it will clear just that key. I will add the ability to call response.session(key) as a getter, for convenience.

from alexa-app.

OverloadUT avatar OverloadUT commented on May 27, 2024

Cool, that'll work! If I want to globally disable the feature I should just be able to put response.clearSession() in pre(), right?

from alexa-app.

matt-kruse avatar matt-kruse commented on May 27, 2024

Or like I say in the other issue, app.persistentSession=false to disable it entirely. :)

from alexa-app.

Related Issues (20)

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.