In Stratox, you only need to memorize one function for binding events: bind. This function works by binding a view instance to an event, making it straightforward to modify the view's component properties. It automatically refreshes the component with the updated data, ensuring the UI stays in sync with your application state.
Creating an Event
In the example below, when the user clicks the "Increment +" button, a new value is added to the props object, and the view is automatically refreshed to reflect the change.
You can disable automatic updates and refreshes by setting the second argument of bind to false. This allows you to manually control when a view or its components should refresh.
// Bind function to add a new item to the listconsthandleAddList=this.bind((props, view, item, event) => {props.increment +=1;// Manually update and refresh the viewview.update();},false);
This flexibility gives you full control over your app’s performance, allowing you to refresh components only when necessary.
Why Not Always Refresh the View?
Refreshing the entire view isn't always desirable. For example, if you bind an oninput event to a text field, you wouldn't want the whole view to refresh each time a user types. Instead, you want the text field's value to update without re-rendering the entire view.
By using this with the bind function, you can access the current component. This means you can also bind events to child components or specific parts of the layout.
What’s Cool?
In this example, only the IncrementUp component will refresh when the event is triggered, even though the button controlling the event is outside the IncrementUp component. This allows for efficient updates while maintaining precise control over the layout.