Giter Club home page Giter Club logo

Comments (2)

nalexn avatar nalexn commented on May 13, 2024 1

Hey @zrfrank

Publishers in Combine maintain type information as you chain them. In the following example, the publisher variable will have the type Publishers.Debounce<Publishers.Delay<Just<Int>, RunLoop>, RunLoop>:

let publisher = Just<Int>(10)
    .delay(for: .seconds(1), scheduler: RunLoop.main)
    .debounce(for: .seconds(1), scheduler: RunLoop.main)

So if we need to return this value from a function, we'd have to specify the full type information as the return type of the function. This would be crazy inconvenient and would lead to tight coupling between the function implementation and the consumers of this function: every time you change this chain of operators (even by swapping delay and debounce), the resulting type changes, so you'll have to update not only the public function's declaration but also all the places in your app calling it.

Just the same problem exists for SwiftUI views: the resulting view type might be insanely long for exposing this as the return type. That's why in Swift 5 there is some keyword, which maintains the entire static type information for the compiler but obscures it for the human.

We could have used some keyword approach with publishers as well, but:

  1. some does not allow you to specify the associated parameters. SwiftUI views do not have those, while publishers have Value and Error
  2. Maintaining the type information is essential for SwiftUI views: this allows the drawing engine to perform the hierarchy diffing in a faster manner. Publishers don't require anything like that, so type information can be safely erased.

I hope my explanation makes sense - let me know if any clarification is needed.

from clean-architecture-swiftui.

zrfrank avatar zrfrank commented on May 13, 2024

Thanks! Really excellent explanations!

from clean-architecture-swiftui.

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.