Coder Social home page Coder Social logo

Triggering Action about reactorkit HOT 5 CLOSED

reactorkit avatar reactorkit commented on May 22, 2024
Triggering Action

from reactorkit.

Comments (5)

zdnk avatar zdnk commented on May 22, 2024

you need to subscribe to it so it is not disposed/deallocated right away.

from reactorkit.

asyl avatar asyl commented on May 22, 2024

@zdenektopic you mean it needs to subscribe to Action?

from reactorkit.

devxoul avatar devxoul commented on May 22, 2024

@asyl,

  1. I didn't understand 'triggering the Action without subscribing to State'. Could you please share me some detailed situation?

  2. You should always return Observable from mutate(). Returning .empty() is also my preferred way but it would be better to use like:

    return Observable.create { [weak self] in
      self?.userService.appendKey(key)
      return Disposables.create()
    }

from reactorkit.

asyl avatar asyl commented on May 22, 2024

@devxoul Thank you.

Scenario

I used ReactorKit and realized that my actions really work when I subscribe to the State.
For example:
I have UI components bound to some action in my Reactor

self.button.rx.tap
  .flatMap { self.textField.rx.text }
  .map { Reactor.Action.appendElement($0) }
  .bind(to: reactor.action)
  .disposed(by: disposeBag)

where Action:

enum Action {
  case appendElement(String)
}

and in mutate(action: Action) function, I have only one Side Effect where I save my element into the disk. But it doesn't work. Even break points don't work unless I create Mutation and State for this case and I subscribe to the State in my View, like this:

reactor.state.map { $0.element }
  .subscribe { print($0) }
  .disposed(by: disposeBag)

After all of that, I can see how break points stop in mutate(action: Action) and function works.

Question

How can I bind my UI components toAction without creating any Mutation & State?

from reactorkit.

devxoul avatar devxoul commented on May 22, 2024

Ah, I got it. You may want to create a state stream without binding it to the view. Try this:

class MyReactor {
  init(params: MyParameters) {
    self.initialState = State(foo: bar)
    _ = self.state // add this line to create a state immediately
  }
}

from reactorkit.

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.