Skip to main content
logo

What is VarState?

VarState is a Python Package For Managing Data ReactJS State-Like.

Features

  • Create, Update, Delete State
  • Create, Update, Delete Events
  • Simple & Quick. (Easy to Use)
  • Fast Performance

Quick Documentation

Creating State

from varstate import State
# Importing State

state = State()
get, update = state.create(-1) # Now we created a state that has value -1.
# i will use -1 for this document. You can put whatever you want.

# Now we have two functions.
# get() for getting value, and
# update(any) to update our value.

Updating

# We can change the value with update() function.
# function takes one argument, the argument will be new value.

print(get()) # Print current value
update(1) # Updating the value to 1
print(get()) # Print updated value

Deleting

# If you finished your works with state, you can delete from the memory.
# just call the <State>.delete()!

state.delete() # Deleted the events and value.

Events

# You can use events for run some functions.
# Example;

from varstate import State
# Importing State

state = State()
# Before calling create, let's create the events.
state.before_create(lambda value: print(f"Creating state with {value}, type: {type(value)}"))
# before_create runs before state creates.
state.after_create(lambda value: print(f"Created state with {value}, type: {type(value)}"))
# after_create runs after state created.

get, update = state.create(-1)
# When you run the program, it will print:
# Creating state with -1, type: <class 'int'>
# Created state with -1, type: <class 'int'>

before_create

# This event runs when started to create a state.
# Takes one argument, the value that will be create.

from varstate import State

state = State()
state.before_create(lambda value: print(f"Creating state with {value}, type: {type(value)}"))

# NOTE: also you can use function like this;
def before_create_function(value):
    print(f"Creating state with {value}, type: {type(value)}")

state.before_create(before_create_function)

# Creating the state
get, update = state.create(-1)

after_create

# This event runs when created a state.
# Takes one argument, the value that created.

from varstate import State

state = State()
state.after_create(lambda value: print(f"Created state with {value}, type: {type(value)}"))

# Creating the state
get, update = state.create(-1)

before_update

# This event runs when started to update the data.
# Takes two argument, first one is the value, second one is the new value will update.

from varstate import State

state = State()
state.before_update(lambda now, future: print(now, future))

# Creating the state
get, update = state.create(-1)

print(get())
update(1)
print(get())

after_update

# This event runs when updated the data.
# Takes two argument, first one is the updated value, second one is the old value.

from varstate import State

state = State()
state.after_create(lambda now, old: print(f"{old} updated to {now}."))

# Creating the state
get, update = state.create(-1)

print(get())
update(1)
print(get())

should_update

# This event checks should data updated.
# Takes two argument, first one is the value, second one is the new value will update.
# Also function should return a boolean.

from varstate import State

state = State()
state.should_update(lambda now, future: future % 2 == 0) # Now it will only update if new data is even.

# Creating the state
get, update = state.create(-1)

print(get())
update(1) # Not updating
print(get())
update(2) # Updating
print(get())

before_delete

# This event runs before delete function runs.

from varstate import State

state = State()
state.before_delete(lambda: print("please don't delete me ;("))

# Creating the state
get, update = state.create(-1)

print(get())
update(1)
print(get())

state.delete()

Metadata

Release files for varstate 0.0.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for varstate 0.0.1
File Size Uploaded
varstate-0.0.1.tar.gz 3.7 kB Details

Release files / varstate-0.0.1.tar.gz

Download URL varstate-0.0.1.tar.gz
Size 3.7 kB
Tags Source
SHA-256 checksum
How to use checksums
5f1ca97d22ab7e6e55f505b4f7529d939c270f059d49343eb703626d115692c8
BLAKE2b-256 checksum
How to use checksums
c45f61b78d910dbeb53814d9ba598bfc1a1bf80c3a7ab27e099739298356ddd4
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.22.0 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.8.5

Release history Release notifications | RSS feed

This release

0.0.1 This release

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page