Skip to content

Instantly share code, notes, and snippets.

View alexobenauer's full-sized avatar

Alexander Obenauer alexobenauer

View GitHub Profile
@alexobenauer
alexobenauer / Todos.js
Last active January 29, 2020 18:30
A Svelte store to access items from Userbase. For use in the tutorial at: *URL when published*
import { writable } from 'svelte/store';
/** STATE **/
/// This simply defines the initial state, and serves as a guide for the structure
const state = {
initialized: false,
todos: []
}
@alexobenauer
alexobenauer / UserAccount.js
Last active November 20, 2022 16:01
A Svelte store for creating and accessing Userbase user accounts, for use in the tutorial at: *URL when published*
import { writable } from 'svelte/store';
/** STATE **/
/// This simply defines the initial state, and serves as a guide for the structure
const state = {
initialized: false,
signedIn: false,
username: undefined,
error: undefined
@alexobenauer
alexobenauer / SwiftUI-EnvironmentObjectExample.swift
Last active June 11, 2019 14:23
How EnvironmentObjects work in SwiftUI views
//
// SwiftUI-EnvironmentObjectExample.swift
// SwiftUI-DataFlowExamples
//
// Part of the series beginning at:
// https://medium.com/@alexobenauer/demystifying-data-flow-through-swiftui-697017aba7e0
//
import SwiftUI
import Combine
@alexobenauer
alexobenauer / SwiftUI-ObjectBindingExample.swift
Created June 11, 2019 01:12
How ObjectBindings work in SwiftUI views
//
// SwiftUI-ObjectBindingExample.swift
// SwiftUI-DataFlowExamples
//
// Part of the series beginning at:
// https://medium.com/@alexobenauer/demystifying-data-flow-through-swiftui-697017aba7e0
//
import SwiftUI
import Combine
@alexobenauer
alexobenauer / SwiftUI-BindingExample.swift
Last active June 11, 2019 00:49
How bindings work in SwiftUI views
//
// SwiftUI-BindingExample.swift
// SwiftUI-DataFlowExamples
//
// Part of the series beginning at:
// https://medium.com/@alexobenauer/demystifying-data-flow-through-swiftui-697017aba7e0
//
import SwiftUI
@alexobenauer
alexobenauer / SwiftUI-StateExample.swift
Last active June 11, 2019 00:24
How state works in SwiftUI views
//
// SwiftUI-StateExample.swift
// SwiftUI-DataFlowExamples
//
// Part of the series beginning at:
// https://medium.com/@alexobenauer/demystifying-data-flow-through-swiftui-697017aba7e0
//
import SwiftUI
@alexobenauer
alexobenauer / SwiftUI-PropertyExample.swift
Last active June 11, 2019 00:02
How properties work in SwiftUI views
//
// SwiftUI-PropertyExample.swift
// SwiftUI-DataFlowExamples
//
// Part of the series beginning at:
// https://medium.com/@alexobenauer/demystifying-data-flow-through-swiftui-697017aba7e0
//
import SwiftUI
import Cocoa
class ViewController: NSViewController, StoreSubscriber {
@IBOutlet weak var counterLabel: NSTextField!
override func viewDidLoad() {
super.viewDidLoad()
store.subscribe(self)
let store = Store(reducer: appReducer, state: nil)
struct AppState: State {
var counter: Int = 0
}
struct IncreaseAction: Action {
let increaseBy: Int
}
@alexobenauer
alexobenauer / SimpleRedux.swift
Created December 5, 2017 16:39
Dead simple Redux implementation in Swift. Meant for educational purposes only, not for production!
import Foundation
protocol Action { }
protocol State { }
typealias Reducer = (_ action: Action, _ state: State?) -> State
protocol StoreSubscriber {
func newState(state: State)