slash.core
This module contains the Slash core classes.
- class slash.core.Attr(name)
Bases:
propertyProperty class representing an attribute of an element.
- Parameters:
name (str) – Name of the attribute.
- class slash.core.Elem(tag, *children, **attrs)
Bases:
objectBase class for all Slash elements.
- Parameters:
- add_class(name)
Add one or more classes to element.
- append(*children)
Append to the children of this element.
- attrs()
Get element attributes.
- contains(elem)
Check if another element is contained by this element.
- insert(position, *children)
Insert into the children of this element at given position.
- is_mounted()
Check if element is mounted.
- Returns:
Boolean indicating if element is mounted.
- Return type:
- onmount(handler)
Add event handler for mount event.
- onunmount(handler)
Add event handler for unmount event.
- remove_attr(name)
Remove attribute from element.
- remove_class(name)
Remove one or more classes from element.
- set_attr(name, value='')
Set attribute of element.
- style(style)
Update CSS style of element.
- class slash.core.History
Bases:
objectClass representing the JavaScript
window.historyobject.- back()
Call the JavaScript
window.history.backmethod.- Return type:
None
- forward()
Call the JavaScript
window.history.forwardmethod.- Return type:
None
- onpopstate(handler)
Add event handler for popstate event.
- Parameters:
handler (Callable[[PopStateEvent], Any] | Callable[[], Any]) – Handler to call on popstate event.
- Return type:
None
- popstate(event)
Trigger popstate event.
- Parameters:
event (PopStateEvent) – Popstate event to be passed to handlers.
- Return type:
None
- push(state, url=None)
Call the JavaScript
window.history.pushStatemethod.
- class slash.core.Location(url)
Bases:
objectClass containing detailed information on client location.
- Parameters:
url (str)
- class slash.core.MountEvent(target)
Bases:
objectEvent that fires when an element is mounted.
- Parameters:
target (Elem) – Element that was mounted.
- class slash.core.Session(server, client)
Bases:
objectThe Session class is used to communicate with the currently-connected user.
- Parameters:
server (Server)
client (Client)
- accept_file(handler)
Create an endpoint for file uploading.
- add_stylesheet(path)
Add stylesheet.
- Parameters:
path (Path) – Path to stylesheet.
- Return type:
None
- call_handler(handler, event)
Call event handler in the context of the session.
- cancel_tasks(msg=None)
Cancel all tasks associated with this session.
- Parameters:
msg (str | None)
- Return type:
None
- create_future()
Create future instance.
- Return type:
Future
- create_task(coroutine)
Create task in the context of the session.
- Parameters:
coroutine (Awaitable[None]) – Awaitable function to run.
- Return type:
None
- static current()
Get the current session.
- Returns:
Current session instance or None.
- Return type:
Session | None
- execute(jsfunction, args, name=None)
Execute a JavaScript function.
- Parameters:
jsfunction (JSFunction) – JavaScript function instance to execute.
args (list[Any]) – List of arguments to provide to the function.
name (str | None) – If set, the output of the function will be stored on the client under this name. The output can later be accessed in JavaScript using
Slash.value(name).
- Return type:
None
- async flush()
Send all queued messages to the client.
- Return type:
None
- get_data(key)
Get value in local storage.
- get_elem(id)
Get element by id.
- log(message, *, level='info', details=None)
Send logging message to the client.
- static require()
Get the current session, or raise an error if there is none.
- Returns:
Current session instance.
- Raises:
RuntimeError – If there is no current session.
- Return type:
- send(message)
Send a message to the client.
- Parameters:
message (Message) – Message to be sent.
- Return type:
None
- set_data(key, value)
Set value in local storage.
- set_location(url)
Navigate to location.
- Args;
url: URL to navigate to.
- Parameters:
url (str)
- Return type:
None
- set_root(root)
Set root element.
- Parameters:
root (Elem) – Element to set as root element.
- Return type:
None