Package: varstate
What is VarState?VarState is a Python Package For Managing Data ReactJS State-Like.FeaturesCreate, Update, Delete StateCreate, Update, Delete EventsSimple & Quick. (Easy to Use)Fast PerformanceQuick DocumentationCreating StatefromvarstateimportState# Importing Statestate=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 valueupdate(1)# Updating the value to 1print(get())# Print updated valueDeleting# 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;fromvarstateimportState# Importing Statestate=State()# Before calling create, let's create the events.state.before_create(lambdavalue:print(f"Creating state with{value}, type:{type(value)}"))# before_create runs before state creates.state.after_create(lambdavalue: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.fromvarstateimportStatestate=State()state.before_create(lambdavalue:print(f"Creating state with{value}, type:{type(value)}"))# NOTE: also you can use function like this;defbefore_create_function(value):print(f"Creating state with{value}, type:{type(value)}")state.before_create(before_create_function)# Creating the stateget,update=state.create(-1)after_create# This event runs when created a state.# Takes one argument, the value that created.fromvarstateimportStatestate=State()state.after_create(lambdavalue:print(f"Created state with{value}, type:{type(value)}"))# Creating the stateget,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.fromvarstateimportStatestate=State()state.before_update(lambdanow,future:print(now,future))# Creating the stateget,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.fromvarstateimportStatestate=State()state.after_create(lambdanow,old:print(f"{old}updated to{now}."))# Creating the stateget,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.fromvarstateimportStatestate=State()state.should_update(lambdanow,future:future%2==0)# Now it will only update if new data is even.# Creating the stateget,update=state.create(-1)print(get())update(1)# Not updatingprint(get())update(2)# Updatingprint(get())before_delete# This event runs before delete function runs.fromvarstateimportStatestate=State()state.before_delete(lambda:print("please don't delete me ;("))# Creating the stateget,update=state.create(-1)print(get())update(1)print(get())state.delete()