redux-capi

redux-capi

    ›API Specs

    Introduction

    • What it is
    • Usage
    • Rationale
    • Context

    API Specs

    • API Spec
    • Redactions
    • Selectors
    • Thunks
    • Mounting
    • Composing
    • Validation

    Reference

    • createAPI
    • API
    • api.mount()
    • api.mock()
    • Injection
    • Utilities

    Examples

    • Todo List

    API specification

    APIs are defined by a specification that uses JSON to define redactions, selectors and thunks. You may define them all together or split them apart depending on how complex your API is.

    import { createAPI} from 'redux-capi';
    const MyAPISpec = {
        redactions: redactions definitions ...,
        selectors: selector definitions ...,
        thunks: thunk definitions ...
    }
    export const myAPI = createAPI(MyAPISpec)
    

    Results of API

    Every property you define under redactions, selectors and thunks results in a property in the final API once it is used in a component or test.

    Redactions result in self-dispatching functions that are dispatched using the standard redux dispatch from the store

    Selectors result in properties that have the selected value.

    Thunks result in functions that use the redux-thunk mechanism but are wrapped to provide the context

    Breaking the Spec into Smaller Pieces

    Because the context is passed to most functions in the spec there is no need for functions to reference the spec itself. Instead they reference the results of the API just as a component would reference them. This means that you can define them in multiple files and group them together in whatever way makes sense for the logic of your API.

    Combining the Pieces with Arrays

    You can combine subject areas like this:

    const part1 = {
        redactions: some redactions ...
        thunks: some thunks ...
    }     
    const part2 = {
        redactions: some more redactions ...
        selectors: some selectors ...
    }
    myAPI = createAPI([part1, part2])     
    
    ← ContextRedactions →
    redux-capi
    Docs
    Getting Started (or other categories)Guides (or other categories)API Reference (or other categories)
    Community
    User ShowcaseStack OverflowProject ChatTwitter
    More
    BlogGitHubStar
    Facebook Open Source
    Copyright © 2020 Sam Elsamman