Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

Where do I start with simple JavaScript state management?

Options
  • 18-10-2015 8:11pm
    #1
    Closed Accounts Posts: 4,763 ✭✭✭


    I have a pair of elements that need to be toggled based on:
    • Window size.
    • Window scroll position.
    • On click.

    Scroll
    It's a navigational menu and its toggle button. At bigger sizes, the menu appears. When I scroll down, the menu is hidden and the button appears, and vice versa.

    Click
    When the menu button is clicked, the menu appears until the window is scroll or resized, and their conditions are evaluated again.

    Resize
    When the window is below a certain size, the scroll action is disabled, and the menu is permanently hidden unless the menu button is clicked.

    Thing is, I have all three actions running separately, but I just cannot conceive of a way to link all three together, that is: to tie each action to a central variable which tracks state and propagates a change when a condition is met. I turn up a complete blank, and I don't know what's the best solution.

    Where do I start with this sort of problem?


Comments

  • Registered Users Posts: 11,979 ✭✭✭✭Giblet


    You want something like observables. Lot's of libraries support this, look at Knockout or something similar.


  • Closed Accounts Posts: 4,763 ✭✭✭Fenster


    Will give it a try, thank you sir!


Advertisement