Giter Site home page Giter Site logo

Comments (7)

geekygrappler avatar geekygrappler commented on August 18, 2024 1

Hey, @justinaray we have maxAge option, which takes a time in seconds, so I've documented that on the Readme. Does that work as an alternative to overloading expires?

from ember-cookies.

marcoow avatar marcoow commented on August 18, 2024

I'm not sure this is something that's actually needed to be honest, especially as we'd just be adding shortcuts that's already very simple, e.g. For 3 days:

3 * 24 * 60 * 60

Also if you treat expires: 3 as 3 days how would you distinguish that from a 3 second expiry?

from ember-cookies.

justinaray avatar justinaray commented on August 18, 2024

Completely agree that it's trivial, but you do have to pass a Date instance for expires, right? So it's a bit more involved.

this.get('cookies').write(MY_COOKIE_NAME, cookieVal, {
...
expires: new Date(Date.now() + 3 * 24 * 60 * 60 * 1000) // Raw Date approach
expires: moment().add(3, 'days').toDate() // Moment approach
...
}

Again, this is pretty straightforward to write, but I saw it and immediately thought of a utility so I suggested it. To me, this seems easier:

this.get('cookies').write(MY_COOKIE_NAME, cookieVal, {
...
expires: '3d' // 3 days
...
}

Completely up to you as a maintainer, but just thought I'd suggest it. Thanks again for the addon!


Re: Number param

I also agree that a Number value for expires is ambiguous. I just suggested days as a default as it's consistent with the other cookie libraries. I guess they assume standard cookie duration is in days? Had I designed the api for those other libraries, I would have probably supported a String variant with value/units as I suggested above.

from ember-cookies.

marcoow avatar marcoow commented on August 18, 2024

but you do have to pass a Date instance for expires, right?

Good point ;) I guess allowing to pass a number (and treating this as "seconds from now") would actually be a good idea then.

I'd actually not want to allow strings like '3d' - if we allow passing seconds I think there's very little need for something like this and we'd add a custom vocabulary that mostly adds unnecessary complexity to the library. The main idea behind ember-cookies is to provide a cooke abstraction that works both in the browser as well as on the server and not really to provide a fancy API on top of cookies.

from ember-cookies.

justinaray avatar justinaray commented on August 18, 2024

Seconds seems like a good and flexible default to me! Easy to do the maths from there as you initially commented.

Would you prefer to overload expires as we've been chatting about or add another option key for the seconds config?

I am pretty swamped with work as I am sure you are as well. Just wanted to hash out the api in case I find some time this weekend to look into a PR.


Aside (Again working through the API)

Millis are usually the standard time manipulation unit, but since cookies only have second precision, I think that's perfectly fine to use seconds as the default here and not to go to that level of precision in this API.

from ember-cookies.

marcoow avatar marcoow commented on August 18, 2024

Would you prefer to overload expires as we've been chatting about or add another option key for the seconds config?

I think overloading should be fine.

Millis are usually the standard time manipulation unit, but since cookies only have second precision, I think that's perfectly fine to use seconds as the default here and not to go to that level of precision in this API.

max-age is in seconds as well (see https://developer.mozilla.org/en-US/docs/Web/API/document/cookie) so I think seconds should be fine.

from ember-cookies.

justinaray avatar justinaray commented on August 18, 2024

Thanks @geekygrappler and @marcoow. Max-Age will work for our use case, seems to have pretty good browser support, and MDN says it will be preferred over Expires if both are set and supported.

👍

from ember-cookies.

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.