Giter Site home page Giter Site logo

Reduce boilerplate in Actions about katana-swift HOT 7 CLOSED

okla avatar okla commented on August 22, 2024
Reduce boilerplate in Actions

from katana-swift.

Comments (7)

bolismauro avatar bolismauro commented on August 22, 2024

Hi!
Thanks for the input. You're completely right and we are aware of this problem. We decided 2 years ago to don't use that approach because of the issues with PAT and all the additional complications that they bring on the table. Moreover, it creates also some issues when it comes to Modularization and actions offered by libraries.

We are exploring different approaches for the next version of Katana, but in the meanwhile what we do it to use an additional protocol like this

protocol AppAction: Action {
  func updatedState(currentState: inout AppState)
}

extension AppAction {
  public func updatedState(currentState: State) -> State {
    guard var state = currentState as? AppState else {
      fatalError()
    }
    self.updatedState(currentState: &state)
    return state
  }
}

You can do the same thing for the AsyncAction. It is not perfect for sure, but it is quite handy

from katana-swift.

okla avatar okla commented on August 22, 2024

an additional protocol like this

Maybe it's better to encourage this approach by adding some TypedAction: Action protocol right to Katana instead of enforcing users to implement it by themselves.

Another place where boilerplate can be reduced a bit is AsyncAction – default implementations for updatedStateFor... methods can be added to protocol extension

func updatedStateFor...(currentState: State) -> State {
  return currentState
}

next version of Katana

Any hint about when it may be released?

from katana-swift.

bolismauro avatar bolismauro commented on August 22, 2024

It is actually a good idea :) Feel free to open a PR!

For the next version, we are starting to discuss it in these days. Since we have several different priorities, we will try to figure out how to prioritise them. If Katana ends up "winning", I expect this to happen in the next months (1/2 max).

About a year ago I wrote an evolution proposal, which was very ELM oriented and very radical. You can find it here
https://github.com/bolismauro/katana-evolution

It may be that we will use some of that ideas, but for sure it will become 100% compatible with the current version as we have several tens of apps that use Katana and update them all together would be crazy

from katana-swift.

bolismauro avatar bolismauro commented on August 22, 2024

As discussed, the new katana experimental version offers typed versions of the actions (state updaters and side effects actually, actions have been separated).

We are developing a couple of apps using this experimental version, so it is not really production ready yet.

Thanks a lot for the input!

from katana-swift.

okla avatar okla commented on August 22, 2024

The link isn't working(

from katana-swift.

bolismauro avatar bolismauro commented on August 22, 2024

https://github.com/BendingSpoons/katana-swift/tree/experimental

sorry ;)

from katana-swift.

okla avatar okla commented on August 22, 2024

Thanks, I'll give it a look!

from katana-swift.

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.