|
''' |
|
title: session |
|
''' |
|
|
|
import simplestart as ss |
|
|
|
ss.md("## ss.session - reactive session variables") |
|
ss.md("By modifying the session variable, the view can be automatically re-rendered") |
|
|
|
ss.space() |
|
|
|
ss.md(''' |
|
--- |
|
#### π
Example 1 - Basic |
|
''') |
|
|
|
|
|
|
|
ss.session["count"] = 100 |
|
|
|
mytext = ss.text("The couns is @count") |
|
|
|
|
|
def change_count(): |
|
ss.session.count += 1 |
|
|
|
ss.button("Add Count", onclick=change_count) |
|
|
|
ss.write(''' |
|
--- |
|
#### π Code |
|
''') |
|
|
|
ss.md(''' |
|
```python |
|
import simplestart as ss |
|
|
|
ss.session["count"] = 100 |
|
|
|
mytext = ss.text("The couns is @count") |
|
|
|
|
|
def change_count(): |
|
ss.session.count += 1 |
|
|
|
ss.button("Add Count", onclick=change_count) |
|
|
|
``` |
|
''') |
|
|
|
ss.space() |
|
|
|
ss.md(''' |
|
--- |
|
#### π
Example 2 - Dict |
|
''') |
|
|
|
student = { |
|
"name":"Sam", |
|
"age":18, |
|
"gender":"Male", |
|
"favorite": "Sport, movie" |
|
} |
|
|
|
ss.session.data = student |
|
|
|
ss.markdown(''' |
|
### Student Info |
|
**Name:** @data.name |
|
**Age:** @data.age |
|
**Gender:** @data.gender |
|
**Favorite:** @data.favorite |
|
''') |
|
|
|
def change_student(event): |
|
student = { |
|
"name":"Jane", |
|
"age":17, |
|
"gender":"Female", |
|
"favorite": "Music, painting" |
|
} |
|
ss.session.data = student |
|
|
|
def change_info(event): |
|
ss.session.data["name"] = "Sally" |
|
|
|
ss.button("Change Student", onclick = change_student) |
|
ss.button("Change Info", onclick = change_info) |
|
|
|
ss.write(''' |
|
--- |
|
#### π Code |
|
''') |
|
|
|
ss.md(''' |
|
```python |
|
import simplestart as ss |
|
|
|
student = { |
|
"name":"Sam", |
|
"age":18, |
|
"gender":"Male", |
|
"favorite": "Sport, movie" |
|
} |
|
|
|
ss.session.data = student |
|
|
|
ss.markdown(\''' |
|
### Student Info |
|
**Name:** \@data.name |
|
**Age:** \@data.age |
|
**Gender:** \@data.gender |
|
**Favorite:** \@data.favorite |
|
\''') |
|
|
|
def change_student(event): |
|
student = { |
|
"name":"Jane", |
|
"age":17, |
|
"gender":"Female", |
|
"image":"", |
|
"favorite": "Music, painting" |
|
} |
|
ss.session.data = student |
|
|
|
def change_info(event): |
|
ss.session.data["name"] = "Sally" |
|
|
|
ss.button("Change Student", onclick = change_student) |
|
ss.button("Change Info", onclick = change_info) |
|
|
|
``` |
|
''') |
|
|
|
|