Local Data
Recall the counting button app
page main () initialize ◳ count := 0 display boxed ◳ count → post to wall box → set border(colors → foreground, 0.1) box → on tapped(handler) where handler() is ◳ count := ◳ count + 1 end end end boxed end page
- When you close and resart the app, it is back to zero
- This is in part because the initilize section sets the count variable to 0 every time the app starts
- So if we delete that, nothing happens
- These is because by default global variables are not stored on the user’s device
- They are recreated every time the app is run
- Changing this is easy
- Under ‘global vars’ click on the variable name and click the radio button nexted to ‘local’
- Now the variable is local to the user’s device
- Each device has its own local copy of the variable
Notice that the icon for the variable turned yellow
Cloud Data
- If we publish and load in a different web browser, there are two different counts
- If you want to share that value, click the ‘replicated’ check box
- Note, with replicated data, the user must log in
- Note the cloud icon at the top of the window
- This replicates it across a single user’s device
Can also replicate it across all users by adding the following to the initialize section
cloud → switch to session(cloud data → everyone session)
Note that the cloud icon has changed and the variable icon has turn cyan
Collections
Recall the todo list app we created previously
page main () initialize ◳ todo list := collections ◳ user input := "" display boxed box → set border(colors → foreground, 0.1) box → edit("textline", ◳ user input, changehandler) where changehandler(text : String) is ◳ user input := text end end end boxed boxed "Add" → post to wall box → set border(colors → foreground, 0.1) box → on tapped(handler) where handler() is ◳ todo list → add(◳ user input) end end end boxed for each s in ◳ todo list do s → post to wall end for each end page
- It would be nice if it remembered things we want to do
- So do the same thing as before, remove the initialization
- But without the initialization it breaks, it doesn’t have a default value
Can fix this with an if statement
if ◳ todo list → is invalid then ◳ todo list := collections → create string collection else do nothing end if
- Make it local, but this gives an error, collections can’t be saved
- To solve this need a completely different type of object, a table
- Click ‘add new’, choose ‘see more options’, choose table
- A table is like an Excel spread sheet, there are columns that hold data of a certain type, and rows that are entries in the table
- Rename the table and add a column
- Notice that the icon is yellow, by default they are local
Add to a table is a little more complicated than adding to a collection, because a table can have multiple columns
⌹ ToDo table → add row → thing := ◳ user input
To display the contents
for each ToDo in ⌹ ToDo table do ToDo → thing → post to wall end for each