Skip to content

Latest commit

 

History

History
36 lines (29 loc) · 813 Bytes

API.md

File metadata and controls

36 lines (29 loc) · 813 Bytes

README.md

API

const OpenState = require('openstate');

OpenState.create({
    "strict": true,
    "reactive": Vue.reactive,
});

openstate.addHandlers({
    "Post": {
        "path": "post/:id",
        async read ({ id }) {
            return await client.get(`post/${id}`);
        },
        async create ( input ) {
            const result = await client.create(`post/${id}`, input );

            this.openstate.state[ `post/${result.id}` ] = result;

            return result;
        },
        async update ({ id }, changed ) {
            return await client.update(`post/${id}`, changed );
        },
        validation ( data, rejections ) {
            if ( data.message === undefined )
                rejections.push(`'message' is required`);
        },
    },
});