1.3.0 • Published 5 years ago

djinn-state-history v1.3.0

Weekly downloads
1
License
MIT
Repository
github
Last release
5 years ago

Djinn-state history

Build Status Codacy Badge Codacy Badge

npm.io npm.io npm.io

Djinn-state helpers for history integration

This library is just a wrapper of the history package. The HistoryService have implemented all the exported functions and its parameters of the history package (push, go, goBack, goForward, replace, block, createHref) and with two more functions (pushLocation, replaceLocation) to receive the location object instead of its original ones.

Install

npm npm i --save djinn-state djinn-state-history

yarn yarn add djinn-state djinn-state-history

Using

// djinn.js
import { Djinn } from 'djinn-state';

export const djinn = new Djinn();

// djinnServices.js
import { HistoryService } from 'djinn-state-history';
import { djinn } from './djinn';

djinn.register(HistoryService);
djinn.start();

// index.js
import { HistoryService } from 'djinn-state-history';
import { createBrowserHistory } from 'history';
import { djinn } from './djinn';
import './djinnServices';

const history = createBrowserHistory();
const service = djinn.getService(HistoryService);
service.setHistory(history);

service.push('/home');

Route blocking

Useful for authentication.

// djinn.js
import { Djinn } from 'djinn-state';

export const djinn = new Djinn();

// AuthBlocker.js
import { HistoryBlockerService } from 'djinn-state-history';

export class AuthBlocker extends HistoryBlockerService {
  canAccessRoute(location, action){
    return true; // or false
  }
}

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

djinn.register(AuthBlocker);
djinn.start();

// index.js
import { createBrowserHistory } from 'history';
import { djinn } from './djinn';
import { AuthBlocker } from './AuthBlocker';
import './djinnServices';

const history = createBrowserHistory();
const service = djinn.getService(AuthBlocker);
service.setHistory(history);

service.push('/home');
1.3.0

5 years ago

0.0.3

5 years ago

0.0.2

5 years ago

0.0.1

5 years ago