Skip to content
This repository has been archived by the owner on Oct 19, 2023. It is now read-only.

Commit

Permalink
Dev small performance improvements (#19)
Browse files Browse the repository at this point in the history
* init

* 💥 internal storage clearing support

* npm install + gulp-place

* build

* $dom.component@v1.1.3

* Delete gulp_place.js
  • Loading branch information
jaandrle authored Aug 25, 2020
1 parent 2d11315 commit fc3ddfa
Show file tree
Hide file tree
Showing 18 changed files with 1,598 additions and 1,926 deletions.
2 changes: 1 addition & 1 deletion bin/$dom_component-min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

57 changes: 39 additions & 18 deletions bin/$dom_component.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,20 @@ function init(global){
* @global
*/
/* standalone= "standalone"; */
const component_utils= Object.freeze({
registerToMap: function(store, current, indexGenerator){
let current_index= -1;
for(const [i, v] of store){
if(v===current) current_index= i;
if(current_index!==-1) break;
}
if(current_index!==-1) return current_index;
current_index= indexGenerator();
store.set(current_index, current);
return current_index;
},
indexGenerator: (index= 0)=> ()=> index++
});
/**
* In generall, all methods from {@link module:jaaJSU~$dom~instance_component} don't do anything. Also during "mounting" there are some changes see method {@link module:jaaJSU~$dom~instance_componentEmpty.mount}.
* @typedef instance_componentEmpty
Expand Down Expand Up @@ -102,7 +116,7 @@ function init(global){
* This 'functional class' is syntax sugar around [`DocumentFragment`](https://developer.mozilla.org/en-US/docs/Web/API/DocumentFragment) for creating DOM components and their adding to live DOM in performance friendly way.
* @method component
* @memberof module:jaaJSU~$dom
* @version 1.1.2
* @version 1.1.3
* @see {@link https://github.com/jaandrle/dollar_dom_component}
* @param {string} [el_name= EMPTY] Name of element (for example `LI`, `P`, `A`, …). This is parent element of component. By default the "empty" element is generated. See {@link module:jaaJSU~$dom~instance_component.add}.
* @param {module:jaaJSU~$dom~DomAssignObject} attrs The second argument for {@link module:jaaJSU~$dom.assign}
Expand Down Expand Up @@ -521,7 +535,10 @@ function init(global){
assign= undefined;
createElement= undefined;
container= undefined;
internal_storage= undefined;
if(internal_storage&&internal_storage.clear){
internal_storage.clear();
internal_storage= undefined;
}
component_out= undefined;
add_out_methods= undefined;
return null;
Expand Down Expand Up @@ -609,17 +626,15 @@ function init(global){
* @returns {Object} `{ register, registerComponent, update, unregister}`
*/
function initStorage(){
const /* storage for component, functions for updates and mapping data keys and corresponding elements */
data= {},
components= [], els= new Map(),
functions= new Map(),
listeners= new Map();
let
counter= 0;
const
{ registerToMap, indexGenerator }= component_utils;
let /* storage for component, functions for updates and mapping data keys and corresponding elements */
data, components, els, functions, listeners, getIndex;
internalVars(indexGenerator(0));
return {
register: function(el, init_data, fun){
Object.assign(data, init_data);
const ids= registerToMap(els, el)+"_"+registerToMap(functions, fun);
const ids= registerToMap(els, el, getIndex)+"_"+registerToMap(functions, fun, getIndex);
const init_data_keys= Object.keys(init_data);
for(let i=0, i_key, i_length= init_data_keys.length; i<i_length; i++){
i_key= init_data_keys[i];
Expand Down Expand Up @@ -661,11 +676,25 @@ function init(global){
assign(el, new_data);
}
},
clear: function(){
internalVars();
},
getData: function(){
return data;
},
unregister
};
function internalVars(initIndex){
data= {};

components= [];
els= new Map();

functions= new Map();
listeners= new Map();

getIndex= initIndex;
}
function unregister(el_id, fun_id, data_keys){
let funcs_counter= 0;
els.delete(el_id);
Expand All @@ -678,14 +707,6 @@ function init(global){
if(!funcs_counter) functions.delete(fun_id);
function el_idFilter(ids){ return Number(ids.split("_")[0])!==el_id; }
}
function registerToMap(store, current){
let current_index= -1;
store.forEach(function(v, i){ if(current_index===-1&&v===current) current_index= i; });
if(current_index!==-1) return current_index;
current_index= counter++;
store.set(current_index, current);
return current_index;
}
}

/**
Expand Down
Loading

0 comments on commit fc3ddfa

Please sign in to comment.