Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

idea on how sessions might be implemented #771

Closed
wants to merge 1 commit into from
Closed

Conversation

rmorshea
Copy link
Collaborator

@rmorshea rmorshea commented Jun 22, 2022

Description

A draft of what session management might look like in ReactPy based on: https://github.com/phihos/idom-auth-example-sanic

Usage might look like:

from sanic import Sanic
from reactpy import component
from reactpy.backend.sanic import configure, Options
from reactpy.backend.utils import SessionManager, SessionState

poor_mans_db = {}

async def create_session_state():
    id = ...
    poor_mans_db[id] = state = SessionState(
        id=id,
        value=...,
        expiry_date=...,
    )
    return state

async def read_session_state(id):
    return poor_mans_db.get(id)

async def update_session_state(state):
    poor_mans_db[state.id] = state

session_manager = SessionManager(
    create=create_session_state,
    read=read_session_state,    
    update=update_session_state,
)

@component
def MyComponent():
    session = session_manager.use_context()

app = Sanic()
configure(app, MyComponent, Optiona(session_manager=session_manager)

Checklist:

Please update this checklist as you complete each item:

  • Tests have been included for all bug fixes or added functionality.
  • The changelog.rst has been updated with any significant changes.
  • GitHub Issues which may be closed by this Pull Request have been linked.
  • I have left irrelevant checklist items unchecked instead of removing them.

@rmorshea rmorshea force-pushed the draft-session branch 2 times, most recently from 2d0cc0f to 2b7cd07 Compare June 22, 2022 08:05
@Archmonger
Copy link
Contributor

I'll help brainstorm the interface for this when the time comes around.

I would suggest this as a v2 task.

@rmorshea
Copy link
Collaborator Author

rmorshea commented Nov 1, 2022

closing for now

@rmorshea rmorshea closed this Nov 1, 2022
@Archmonger Archmonger deleted the draft-session branch June 19, 2023 04:35
@Archmonger Archmonger restored the draft-session branch June 19, 2023 04:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants