Giter Club home page Giter Club logo

Comments (7)

ara303 avatar ara303 commented on August 31, 2024 1

Fair enough! You know, this struck me as something that is so obvious to do initially, I hadn't considered that there may be a good reason you couldn't.

I'll close. Thanks for educating me!

from halfmoon.

TheKingDave avatar TheKingDave commented on August 31, 2024 1

@edadams yes cookies and localStorage can only store Strings, but you could parse/serialize the bool in the isDarkModeOn/setDarkModeOn methods. Which is a lot cleaner than for the user to check for yes and know the name of the cookie (darkMode).

Example (cookie, could also be implemented with localStorage 😉):

function isDarkModeOn() {
  return this.readCookie('darkModeOn') == 'yes';
}
function setDarkModeOn(darkMode) {
  this.createCookie('darkModeOn', darkMode ? 'yes' : 'no', 365);
}

I would use theme, which is generally used in application/other UI frameworks.

from halfmoon.

halfmoonui avatar halfmoonui commented on August 31, 2024 1

@edadams @TheKingDave
The dark mode cookie implementation has been overhauled in v1.1.0. There is a new method that returns the preferred mode. Again, this returns a string and not a boolean because there are 3 possible values, not just true or false.

Moreover, the setDarkModeOn method is not needed, because there is already halfmoon.toggleDarkMode(). Please refer to this page: https://www.gethalfmoon.com/docs/core-javascript-library/

The docs have been fleshed out, and hopefully everything should be clear now. Regarding the localStorage, I explained my reasoning why that will not be implemented here: #30 (comment)

I will go ahead and close this issue. You can re-open it if you think the issue is still not resolved, or open another issue.

from halfmoon.

halfmoonui avatar halfmoonui commented on August 31, 2024

Hey thanks for bringing this up. Cookie values can only be string. Libraries often allow cookies to store JSON and other data types (such as boolean), but that requires extra parsing before storage and after retrieval. For that reason, "yes" and "no" strings are used. This way, no parsing is required, and the cookie can be read directly.

from halfmoon.

TheKingDave avatar TheKingDave commented on August 31, 2024

I understand the reasoning that the readCookie method returns a string but I would at least create a isDarkModeOn method that returns a boolean. Perhaps also a setDarkModeOn method. These could be used internally. I would not store the darkMode in a String but in a bool. Only in the exception that you would implement themes in the future but then I would rename it to theme and store light and dark.

from halfmoon.

ara303 avatar ara303 commented on August 31, 2024

@TheKingDave Correct me if I've got this wrong but isn't the whole thing that you literally can't store a boolean value in a cookie? My understanding of the answer I got is that a cookie must return a string.

👍 +1 for theme that returns either light or dark. Could be uiTheme or some other more specific name, e.g,m mode or uiMode. (Is the accepted language "dark theme" or "dark mode"?)

That would be a separate issue, I think.


Edit: Guess you could even make an argument for using localStorage instead of cookies at this point, eh? 😉

from halfmoon.

ara303 avatar ara303 commented on August 31, 2024

Riiight! I'm with you now. I've reopened this issue in the hopes it gets looked at since I agree now that you've explained it this way. Hopefully that'll get someone's attention.

from halfmoon.

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.