1
0
Fork 0
mirror of https://github.com/koalyptus/TableFilter.git synced 2024-06-07 00:12:25 +02:00

Added comments

This commit is contained in:
Max Guglielmi 2016-03-20 19:56:18 +11:00
parent e4a048fd2d
commit 4a8613f68b
3 changed files with 95 additions and 11 deletions

View file

@ -7541,7 +7541,7 @@ return /******/ (function(modules) { // webpackBootstrap
/** /**
* Creates an instance of State * Creates an instance of State
* *
* @param tf TableFilter instance * @param {TableFilter} tf TableFilter instance
*/ */
function State(tf) { function State(tf) {
@ -7568,7 +7568,7 @@ return /******/ (function(modules) { // webpackBootstrap
} }
/** /**
* Initialize features state * Initializes the State object
*/ */
@ -7777,7 +7777,21 @@ return /******/ (function(modules) { // webpackBootstrap
return 'onhashchange' in global && (docMode === undefined || docMode > 7); return 'onhashchange' in global && (docMode === undefined || docMode > 7);
}; };
/**
* Manages the URL hash reflecting the features state to be persisted
*
* @export
* @class Hash
*/
var Hash = exports.Hash = function () { var Hash = exports.Hash = function () {
/**
* Creates an instance of Hash
*
* @param {State} state Instance of State
*/
function Hash(state) { function Hash(state) {
_classCallCheck(this, Hash); _classCallCheck(this, Hash);
@ -7786,6 +7800,11 @@ return /******/ (function(modules) { // webpackBootstrap
this.emitter = state.emitter; this.emitter = state.emitter;
} }
/**
* Initializes the Hash object
*/
Hash.prototype.init = function init() { Hash.prototype.init = function init() {
var _this = this; var _this = this;
@ -7806,9 +7825,16 @@ return /******/ (function(modules) { // webpackBootstrap
}); });
}; };
/**
* Updates the URL hash based on a state change
*
* @param {State} state Instance of State
*/
Hash.prototype.update = function update(state) { Hash.prototype.update = function update(state) {
var hash = '#' + JSON.stringify(state); var hash = '#' + JSON.stringify(state);
console.log(hash, this.lastHash, this.lastHash === hash); // console.log(hash, this.lastHash, this.lastHash === hash);
if (this.lastHash === hash) { if (this.lastHash === hash) {
return; return;
} }
@ -7817,6 +7843,14 @@ return /******/ (function(modules) { // webpackBootstrap
this.lastHash = hash; this.lastHash = hash;
}; };
/**
* Converts a URL hash into a JSON object
*
* @param {String} hash URL hash fragment
* @returns {Object} JSON object
*/
Hash.prototype.parse = function parse(hash) { Hash.prototype.parse = function parse(hash) {
if (hash.indexOf('#') === -1) { if (hash.indexOf('#') === -1) {
return null; return null;
@ -7825,18 +7859,33 @@ return /******/ (function(modules) { // webpackBootstrap
return JSON.parse(hash); return JSON.parse(hash);
}; };
/**
* Applies current hash state to features
*/
Hash.prototype.sync = function sync() { Hash.prototype.sync = function sync() {
var state = this.parse(location.hash); var state = this.parse(location.hash);
if (!state) { if (!state) {
return; return;
} }
// To prevent state to react to features changes, state is temporarily
// disabled
this.state.disable(); this.state.disable();
// State is overriden with hash state object
this.state.override(state); this.state.override(state);
// New hash state is applied to features
this.state.sync(); this.state.sync();
// State is re-enabled
this.state.enable(); this.state.enable();
}; };
/**
* Destroy Hash instance
*/
Hash.prototype.destroy = function destroy() { Hash.prototype.destroy = function destroy() {
var _this2 = this; var _this2 = this;

View file

@ -9,16 +9,30 @@ export const hasHashChange = () => {
return ('onhashchange' in global) && (docMode === undefined || docMode > 7); return ('onhashchange' in global) && (docMode === undefined || docMode > 7);
}; };
/**
* Manages the URL hash reflecting the features state to be persisted
*
* @export
* @class Hash
*/
export class Hash { export class Hash {
constructor(state){ /**
* Creates an instance of Hash
*
* @param {State} state Instance of State
*/
constructor(state) {
this.state = state; this.state = state;
this.lastHash = null; this.lastHash = null;
this.emitter = state.emitter; this.emitter = state.emitter;
} }
/**
* Initializes the Hash object
*/
init() { init() {
if(!hasHashChange()){ if (!hasHashChange()) {
return; return;
} }
@ -29,9 +43,14 @@ export class Hash {
Event.add(global, 'hashchange', () => this.sync()); Event.add(global, 'hashchange', () => this.sync());
} }
/**
* Updates the URL hash based on a state change
*
* @param {State} state Instance of State
*/
update(state) { update(state) {
let hash = `#${JSON.stringify(state)}`; let hash = `#${JSON.stringify(state)}`;
console.log(hash, this.lastHash, this.lastHash === hash); // console.log(hash, this.lastHash, this.lastHash === hash);
if (this.lastHash === hash) { if (this.lastHash === hash) {
return; return;
} }
@ -40,6 +59,12 @@ export class Hash {
this.lastHash = hash; this.lastHash = hash;
} }
/**
* Converts a URL hash into a JSON object
*
* @param {String} hash URL hash fragment
* @returns {Object} JSON object
*/
parse(hash) { parse(hash) {
if (hash.indexOf('#') === -1) { if (hash.indexOf('#') === -1) {
return null; return null;
@ -48,18 +73,29 @@ export class Hash {
return JSON.parse(hash); return JSON.parse(hash);
} }
sync(){ /**
* Applies current hash state to features
*/
sync() {
let state = this.parse(location.hash); let state = this.parse(location.hash);
if(!state){ if (!state) {
return; return;
} }
// To prevent state to react to features changes, state is temporarily
// disabled
this.state.disable(); this.state.disable();
// State is overriden with hash state object
this.state.override(state); this.state.override(state);
// New hash state is applied to features
this.state.sync(); this.state.sync();
// State is re-enabled
this.state.enable(); this.state.enable();
} }
/**
* Destroy Hash instance
*/
destroy() { destroy() {
this.state = null; this.state = null;
this.lastHash = null; this.lastHash = null;

View file

@ -3,7 +3,6 @@ import {Hash} from './hash';
import Str from '../string'; import Str from '../string';
import Types from '../types'; import Types from '../types';
/** /**
* Reflects the state of features to be persisted via hash, localStorage or * Reflects the state of features to be persisted via hash, localStorage or
* cookie * cookie
@ -17,7 +16,7 @@ export class State extends Feature {
/** /**
* Creates an instance of State * Creates an instance of State
* *
* @param tf TableFilter instance * @param {TableFilter} tf TableFilter instance
*/ */
constructor(tf) { constructor(tf) {
super(tf, 'state'); super(tf, 'state');
@ -40,7 +39,7 @@ export class State extends Feature {
} }
/** /**
* Initialize features state * Initializes the State object
*/ */
init() { init() {
if (this.initialized) { if (this.initialized) {