Skip to content

Programming Guidelines

theRealProHacker edited this page Feb 27, 2023 · 1 revision

State Management

State Management is a difficult topic. Most programs will (eventually) need global or at least shared state.

In Positron, you are responsible for state management yourself. But I have some tips that might help you.

Use the DOM for state

Let's say you have a list of names that you want to show. You could hold a global list and update the DOM whenever it is changed. But you could also save the list in the DOM and then you don't need the global list anymore. For this the data attributes come in handy. Any attributes of objects you don't want the user to see, you can put into data attributes. You can access these like so:

  1. SingleJ(query).data(key) to get the key attribute
  2. SingleJ(query).data(key, value) to set the key attribute to value