Skip to content
This repository was archived by the owner on Aug 17, 2026. It is now read-only.
This repository was archived by the owner on Aug 17, 2026. It is now read-only.

Optimize the state machine #67

Description

@clearloop

The state machine doesn't work...It's buggy to pass complex data to wasm, we need to use Closure instead of Fn, ref gesture.rs

The syntax of the state machine is hard to use, need to refactor as below

Components without state

struct Hello {
  name: String,
}

impl LifeCyle for Hello {
  fn create(name: String) -> Self {
       Self { name }
  }
  
  fn render(&self) -> Center {
     Center::with(Text::with(&format!("Hello, {}", self.name)))
  }
}

Components with state

struct Counter {
  count: i32,
}

impl LifeCyle for Counter {
  fn create(count: i32) -> Self {
    Self { count }
  }

  fn render(&self) -> GestureDetector {
    GestureDetector::new(
      Text::with(format!("count: {}", &self.count)),
    ).register(Gesture::Tap, |&mut state| state.count += 1)
  }
}

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions