Nuclear - Reactive state management for python
Atoms and Derives
The base element in nuclear is called an atom. You can create one with atom({starting value}).
To create a derivative of an atom (or of another derivative) you can user the derivative({source}) function.
To get or set any atoms or derivatives, you can use the .set() and .get() methods.
To add reactions to changed, you can use the .react() method.
Example program:
base = atom(10) #Creates an atom with value 10
derived = derive(lambda: base.get() * 2) #Creates a derive which will always be equal to base * 2
derived.react(lambda: print('The value of derived was changed))
print(base.get()) # prints 10
print(derived.get()) # prints 20
base.set(20) # prints 'The value of derived was changed'
print(derived.get()) # prints 40
Events and Messages
To allow nuclear to implicitly send events and message, you must initialise it with nuclear.init(globals()).
To create a class that can recieve and send messages, it needs to inherit from Receiver.
To respond to events or messages, you can add methods to your class that follow the format:
For events, on_{your event name}
For messages, receive_{your message name}
Then to send events and messages you can use:
For events, broadcast({your event name})
For messages, send({your message name}, {data})
Example program:
nuclear.init(globals())
class TestClass(Receiver):
def __init__(self):
pass
def on_TestEvent(self):
print('Test Event received')
def receive_TestMessage(self, data):
print(f'TestMessage sent data {data}')
test1 = TestClass()
broadcast('TestEvent') # prints 'Test Event received'
send('TestMessage', 200) # prints 'TestMessage sent data 200'
You can also change the format with nuclear.format({events}, {messages}).
Event Modes
The event mode can be changed with eventMode({chosen mode})
-
explicit: Best performance: If you use this mode, you must tag every object that will receive an event or message withnuclear.event_r({event name}, {object})ornuclear.message_r({message name}, {object}). -
described: Second best performance: If you use this mode, you must run thenuclear.scan()function after you have initialised your objects. -
predicted: Second worst performance: Automatically calls the scan function when you call your first event or message. May not work if you're objects are initialised after the function is called. -
implicit: Worst performance: The default option, will always work.
Release files for nuclearstate 0.1.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| nuclearstate-0.1.1.tar.gz | 4.2 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| nuclearstate-0.1.1-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 8.5 kB
Release files / nuclearstate-0.1.1.tar.gz
| Download URL | nuclearstate-0.1.1.tar.gz |
|---|---|
| Size | 4.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
6069870a255141aa43d6fa80866252d567dbcd969eaf9671db406e8c25fb7868
|
|
BLAKE2b-256 checksum How to use checksums |
bc15a0b2c021c046c556864cd76a670115c64fecf19ae955ef03660334fde984
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.4.1 importlib_metadata/4.0.1 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.9.4
|
Release files / nuclearstate-0.1.1-py3-none-any.whl
| Download URL | nuclearstate-0.1.1-py3-none-any.whl |
|---|---|
| Size | 4.2 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
572f9627f03cd408066d18b70ada6f8e94292f3ca5bea922c2013d6ced2794ce
|
|
BLAKE2b-256 checksum How to use checksums |
010ac37a76ebd7f472275397ad366422867b2be266ec2713e025a35b936bf3a2
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.4.1 importlib_metadata/4.0.1 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.9.4
|