GithubHelp home page GithubHelp logo

marty-suzuki / fluxcapacitor Goto Github PK

View Code? Open in Web Editor NEW
123.0 7.0 7.0 29.02 MB

This is what makes the Flux design pattern possible.

License: MIT License

Ruby 7.07% Swift 90.63% Objective-C 2.30%
flux flux-architecture swift ios

fluxcapacitor's Introduction

marty-suzuki's GitHub stats

fluxcapacitor's People

Contributors

marty-suzuki avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

fluxcapacitor's Issues

An improvement example using Swift4

// Definition
protocol DispatcherValue {
    associatedtype RelatedStoreType: Storable
    associatedtype RelatedActionType: Actionable
}

protocol Storable: Codable {
    associatedtype DispatcherValueType: DispatcherValue
    static var name: String { get }
    static func instatntiate() -> Self?
    init()
    func bind(_ value: DispatcherValueType)
}
extension Storable {
    static var name: String {
        return String(describing: self)
    }

    static func instatntiate() -> Self? {
        // Load store from Disk cache
        return nil
    }
}

protocol Actionable {
    associatedtype DispatcherValueType: DispatcherValue
    func dispatch(_ value: DispatcherValueType)
}
extension Actionable where DispatcherValueType.RelatedStoreType.DispatcherValueType == DispatcherValueType {
    func dispatch(_ value: DispatcherValueType) {
        typealias Store = DispatcherValueType.RelatedStoreType
        let store = Store.instatntiate() ?? Store()
        store.bind(value)
    }
}

// Implementaion
enum UserValue: DispatcherValue {
    typealias RelatedStoreType = UserStore
    typealias RelatedActionType = UserAction
    case id(Int)
}

final class UserStore: Storable, Codable {
    static let shared = UserStore()
    typealias DispatcherValueType = UserValue
    private(set) var id: Int = 0
    required init() {}
    static func instatntiate() -> UserStore? { return .shared }
    func bind(_ value: UserValue) {
        switch value {
        case .id(let value):
            self.id = value
        }
    }
}

class UserAction: Actionable {
    typealias DispatcherValueType = UserValue
}

UserAction().dispatch(.id(100))
print(UserStore.instatntiate()?.id)

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.