0.5.1 • Published 8 months ago

@graph-state/plugin-extend v0.5.1

Weekly downloads
-
License
-
Repository
-
Last release
8 months ago

@graph-state/plugin-ws

Plugin for extend Graph. May use like computed.

Installation

npm i @graph-state/core @graph-state/plugin-extend

or

yarn add @graph-state/core @graph-state/plugin-extend

Get started

import { createState } from '@graph-state/core';
import extendPlugin from '@graph-state/plugin-extend';

export const graphState = createState({
  plugins: [
    extendPlugin({
      User: (cache, graph) => {
        return {
          ...graph,
          someProp: 'test'
        }
      }
    }),
  ],
});

graphState.mutate({
  _type: 'User',
  _id: 'id'
})

graphState.resolve('User:id')
/**
 * _type: 'User',
 * _id: 'id'
 * someProp: 'test'
 */

Extend method

Plugin append new method to GraphState instance

export const graphState = createState({
  plugins: [extendPlugin()],
});

graphState.extendGraph('User:test', (cache, graph) => graph)

Lazy extends

You can add lazy extender.

export const graphState = createState({
  plugins: [extendPlugin()],
});

setTimeout(() => {
  // Extend all User graphs and add extender for next updates.
  graphState.declareExtendGraph('User', (cache, graph) => graph)
}, 1000)
0.5.1

8 months ago

0.5.0

12 months ago

0.4.0

1 year ago

0.3.2

1 year ago

0.3.1

1 year ago

0.3.0

1 year ago

0.2.0

1 year ago