Enoria
  • Home
  • Guide
    • Getting Started
    • Hello world!
    • Widgets
      • Container
      • Column
      • Row
      • Form
      • GridBuilder
      • ListBuilder
      • TextLabel
      • TextButton
      • ImageLabel
      • ImageButton
      • PageLayout
      • ScrollContainer
      • Stack
      • TextBox
      • TextFormField
      • VerticalSpacer
      • HorizontalSpacer
      • Viewport
  • Events
  • State Management
    • Stores
    • Observer
  • Animations
  • Build forms with validation
  • Theming
    • Classes
Powered by GitBook
On this page

Was this helpful?

  1. State Management

Observer

Instead of rebuilding whole widget tree on Store action, it rebuilds only those in the Observer.

-- in your custom widget build method
e.Column({
   SortOrder = Enum.SortOrder.Name,
   Children = {
      e.TextLabel("Counter example with Observer"),
      e.TextButton("Increment", {
         OnClick = function()
            self.Controller:Commit("Increment", {})
         end
      }),
      e.Observer( -- only widgets in this gets rebuilt on Increment
         self.Controller, -- the store
         {'Increment'}, -- action(s) to listen to
         function()
            return e.TextLabel(tostring(self.Controller.State.Counter))
         end -- child builder function
      )
   }
})
PreviousStoresNextAnimations

Last updated 3 years ago

Was this helpful?