Coder Social home page Coder Social logo

How to update App state from JS about seed HOT 5 CLOSED

seed-rs avatar seed-rs commented on May 8, 2024
How to update App state from JS

from seed.

Comments (5)

David-OConnor avatar David-OConnor commented on May 8, 2024

Ran into this myself last night while experimenting with fetch - there's no way, and I'd like to add this soon. Currently, all state changes after the initial load are tracked by elements with attached listeners. I'm not sure if the best approach is to somehow expose the app state (eg allow calling vdom::App:update_dom from the API), or exploit the current listener system for events that 'fire instantly'.

The api example you posted is appropriate (eg call something like seed::update_state().

For your specific example, if you only need to process the state on initial load, you may be able to workaround by calling seed::run() inside your then block. eg something like:

#[wasm_bindgen]
pub fn render() {
    my_exported_Js_bridge(payload();
  
}

#[wasm_bindgen]
pub fn my_exported_js_bridge(my_paylod: &str) -> () {
    // create or process model here. 
   let mut model = Model::dafault();
    // ....
    // then:
    seed::run(model, update, view, "main", None);
}

If you need to do this after init load, need to wait for a fix.

from seed.

rsaccon avatar rsaccon commented on May 8, 2024

Thanks. For init load I actually did something similar as you described, but I will also need this after init load.

from seed.

David-OConnor avatar David-OConnor commented on May 8, 2024

Lastest commit has a working soln to this, but it requires a breaking change to the view func (additional param) I'll publish once cleaned up. (see server integration example)

from seed.

David-OConnor avatar David-OConnor commented on May 8, 2024

Updated as v0.1.12.

from seed.

rsaccon avatar rsaccon commented on May 8, 2024

Works great now. Gonna close this.

from seed.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.