Djinn state vue

djinn-state helpers for vue

Version: 1.0.0 Updated: 01/05/2019

By: djinn-state License: MIT

Downloads Last 30 Days: 35

Djinn-state vue

npm version Build Status Codacy Badge Codacy Badge

Djinn-state helpers for vue

Install

npm npm i --save djinn-state djinn-state-vue

yarn yarn add djinn-state djinn-state-vue

Examples

Using

// djinn.js
import { Djinn, DjinnService } from 'djinn-state';
import { createDjinnConnector } from 'djinn-state-vue';

export const djinn = new Djinn();
export const connect = createDjinnConnector(djinn);


// CounterService.js
export class CounterService extends DjinnService {
  state = {
    count: 0,
  };

  decrement = () => {
    const count = this.state.count - 1;
    this.patch({ count });
  };

  increment = () => {
    const count = this.state.count + 1;
    this.patch({ count });
  };
}

// djinnServices.js
import { djinn } from './djinn';

djinn.register(CounterService);
djinn.start();

// main.js
import './djinnServices.js'

Counter.vue

<template>
    <div>
        <button @click="services.CounterService.decrement()">-</button>
        {{state.CounterService.count}}
        <button @click="services.CounterService.increment()">+</button>
    </div>
</template>

<script>
  import {connect} from './djinn';
  import {CounterService} from './CounterService';

  export default {
    name: 'Counter',
    mixins: [connect({CounterService})],
  };
</script>
Categories: Vue js