Git Product home page Git Product logo

vsm-ios's Introduction

Release Lint CI Contributor Covenant Maintainer

VSM for Apple Platforms

VSM is a reactive architecture that is unidirectional, highly type-safe, behavior-driven, and clean. This repository hosts an open-source swift package framework for easily building features in VSM on app publicly available Apple platforms.

Overview

VSM stands for both "View State Model" and "Viewable State Machine". The first definition describes how a feature in VSM is structured, the second definition illustrates how information flows.

VSM Architecture Diagram)

In VSM, the View renders the State. Each state may provide a Model. Each model contains the data and actions available in a given state. Each action in a model returns one or more new states. Any state changes will update the view.

Learning Resources

  • The VSM Documentation contains a complete framework reference, guides, and other learning resources
  • Open the Demo App to see many different working examples of how to build features using the VSM pattern

Code Introduction

The following are code excerpts of a feature that shows a blog entry from a data repository.

State Definition

The state is usually defined as an enum or a struct and represents the states that the view can have. It also declares the data and actions available to the view for each model. Actions return one or more new states.

enum BlogEntryViewState {
    case initialized(loaderModel: LoaderModeling)
    case loading(errorModel: ErrorModeling?)
    case loaded(blogModel: BlogModeling)
}

protocol LoaderModeling {
    func load() -> AnyPublisher<BlogArticleViewState, Never>
}

protocol ErrorModeling {
    var message: String { get }
    func retry() -> AnyPublisher<BlogArticleViewState, Never>
}

protocol BlogModeling {
    var title: String { get }
    var text: String { get }
    func refresh() -> AnyPublisher<BlogArticleViewState, Never>
}

Model Definition

The discrete models provide the data for a given view state and implement the business logic within the actions.

struct LoaderModel: LoaderModeling {
    func load() -> AnyPublisher<BlogArticleViewState, Never> {
        ...
    }
}

struct ErrorModel: ErrorModeling {
    var message: String
    func retry() -> AnyPublisher<BlogArticleViewState, Never> {
        ...
    }
}

struct BlogModel: BlogModeling {
    var title: String
    var body: String
    func refresh() -> AnyPublisher<BlogArticleViewState, Never> {
        ...
    }
}

View Definition

The view observes and renders the state using the ViewState property wrapper. State changes will automatically update the view.

struct BlogEntryView: View {
    @ViewState var state: BlogEntryViewState = .initialized(LoaderModel())

    var body: some View {
        switch state {
        case .initialized(loaderModel: let loaderModel):            
            ...
            .onAppear { 
                $state.observe(loaderModel.load())
            }
        case .loading(errorModel: let errorModel):
            ...
        case .loaded(blogModel: let blogModel)
            ...
            Button("Reload") {
                $state.observe(blogModel.refresh())
            }
        }
    }
}

This example uses SwiftUI, but the framework is also designed to work seamlessly with UIKit.

For more detailed tutorials and documentation, visit the VSM Documentation

Project Information

Credits

VSM for Apple platforms is owned and maintained by Wayfair.

Contributing

See CONTRIBUTING.md.

Security

See SECURITY.md.

License

VSM for Apple platforms is released under the MIT license. See LICENSE for details.

vsm-ios's People

Contributors

albertbori avatar bdunay3 avatar garypwhite avatar granoff avatar renovate[bot] avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

vsm-ios's Issues

CI and publish actions are not working

Description

CI breaks with the error:

2022-12-27 19:07:30.742 xcodebuild[1364:8266] Writing error result bundle to /var/folders/24/8k48jl6d249_n_qfxwsl6xvm0000gn/T/ResultBundle_2022-27-12_19-07-0030.xcresult
xcodebuild: error: Unable to find a destination matching the provided destination specifier:
		{ platform:iOS Simulator, OS:16.0, name:iPhone 14 }

Source

Checklist

Dependency Dashboard

This issue lists Renovate updates and detected dependencies. Read the Dependency Dashboard docs to learn more.

Open

These updates have all been created already. Click a checkbox below to force a retry/rebase of any.

  • Update GitHub Actions (major) (actions/configure-pages, actions/deploy-pages, actions/stale, actions/upload-pages-artifact, macos, suzuki-shunsuke/github-action-renovate-config-validator)

Detected dependencies

github-actions
.github/workflows/ci.yml
  • maxim-lobanov/setup-xcode v1
  • actions/checkout v4
  • sersoft-gmbh/xcodebuild-action v3
  • sersoft-gmbh/xcodebuild-action v3
  • sersoft-gmbh/xcodebuild-action v3
  • sersoft-gmbh/xcodebuild-action v3
  • sersoft-gmbh/xcodebuild-action v3
  • sersoft-gmbh/xcodebuild-action v3
  • macos 13
.github/workflows/lint.yml
  • actions/checkout v4
  • avto-dev/markdown-lint v1
  • actions/checkout v4
  • suzuki-shunsuke/github-action-renovate-config-validator v0.1.3
.github/workflows/pages.yml
  • maxim-lobanov/setup-xcode v1
  • actions/checkout v4
  • actions/configure-pages v4
  • actions/upload-pages-artifact v2
  • actions/deploy-pages v3
  • macos 13
.github/workflows/stale.yml
  • actions/stale v8

  • Check this box to trigger a request for Renovate to run again on this repository

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.