1
0
Fork 0
mirror of https://github.com/koalyptus/TableFilter.git synced 2024-05-16 21:36:41 +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
*
* @param tf TableFilter instance
* @param {TableFilter} tf TableFilter instance
*/
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);
};
/**
* Manages the URL hash reflecting the features state to be persisted
*
* @export
* @class Hash
*/
var Hash = exports.Hash = function () {
/**
* Creates an instance of Hash
*
* @param {State} state Instance of State
*/
function Hash(state) {
_classCallCheck(this, Hash);
@ -7786,6 +7800,11 @@ return /******/ (function(modules) { // webpackBootstrap
this.emitter = state.emitter;
}
/**
* Initializes the Hash object
*/
Hash.prototype.init = function init() {
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) {
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) {
return;
}
@ -7817,6 +7843,14 @@ return /******/ (function(modules) { // webpackBootstrap
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) {
if (hash.indexOf('#') === -1) {
return null;
@ -7825,18 +7859,33 @@ return /******/ (function(modules) { // webpackBootstrap
return JSON.parse(hash);
};
/**
* Applies current hash state to features
*/
Hash.prototype.sync = function sync() {
var state = this.parse(location.hash);
if (!state) {
return;
}
// To prevent state to react to features changes, state is temporarily
// disabled
this.state.disable();
// State is overriden with hash state object
this.state.override(state);
// New hash state is applied to features
this.state.sync();
// State is re-enabled
this.state.enable();
};
/**
* Destroy Hash instance
*/
Hash.prototype.destroy = function destroy() {
var _this2 = this;

View file

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

View file

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