Skip to content

Instantly share code, notes, and snippets.

View gkaimakas's full-sized avatar
:octocat:
Working from home

George Kaimakas gkaimakas

:octocat:
Working from home
View GitHub Profile
@gkaimakas
gkaimakas / NavigationStackAction.swift
Created December 11, 2022 21:46
NavigationStack + ComposableArchitecture
import Foundation
public enum NavigationStackAction<View> where View: Equatable & Hashable & Codable {
case stackChanged([View])
case destinationRemoved(View)
}
import Combine
public final class Signal<Output, Failure: Error>: Publisher {
let observer: Observer
public static func pipe() -> (Signal, Observer) {
var _observer: Observer? = nil
let signal = Signal { (observer, lifetime) in
import Combine
extension Publishers {
@available(OSX 10.15, iOS 13.0, tvOS 13.0, watchOS 6.0, *)
public struct Materialize<Upstream>: Publisher where Upstream: Publisher {
public typealias Output = Event<Upstream.Output, Upstream.Failure>
public typealias Failure = Never
internal let cancellable = SerialCancellable()
internal let stream: PassthroughSubject<Output, Never>
import Combine
class Lifetime {
static func +(lhs: Lifetime, rhs: @escaping () -> Void) -> () -> Void {
let result: ()->Void = {
lhs.end()
rhs()
}
import Combine
/// Naming and idea where taken from ReactiveSwift
precedencegroup BindingPrecedence {
associativity: right
// Binds tighter than assignment but looser than everything else
higherThan: AssignmentPrecedence
}
import Combine
extension Subscribers {
@available(OSX 10.15, iOS 13.0, tvOS 13.0, watchOS 6.0, *)
public final class SinkEvents<Upstream>: Subscriber where Upstream: Publisher {
public typealias Input = Upstream.Output
public typealias Failure = Upstream.Failure
let lifetime: Cancellable
internal var subscription: Subscription?
<link rel="import" href="../components/polymer/polymer.html">
<polymer-element name="my-element">
<template>
<style>
:host {
position: absolute;
width: 100%;
height: 100%;