-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
π Clear
addElementGetter
and addElementsGetter
cache when rendering
- Loading branch information
Showing
4 changed files
with
67 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
var has_premature_undried_elements, | ||
let has_premature_undried_elements, | ||
originalCreateElement, | ||
creating_element, | ||
observed_attributes = Symbol('observed_attributes'), | ||
|
@@ -155,15 +155,15 @@ Hawkejs._createUnconstructedElement = function _createUnconstructedElement(name) | |
* | ||
* @author Jelle De Loecker <[email protected]> | ||
* @since 1.1.1 | ||
* @version 1.1.1 | ||
* @version 2.3.19 | ||
* | ||
* @param {Element} instance | ||
* | ||
* @return {Object} | ||
*/ | ||
function getPrivate(instance) { | ||
const getPrivate = instance => { | ||
|
||
var map = weak_properties.get(instance); | ||
let map = weak_properties.get(instance); | ||
|
||
if (!map) { | ||
map = { | ||
|
@@ -176,16 +176,18 @@ function getPrivate(instance) { | |
// Attribute string values | ||
values : {}, | ||
|
||
// New values that are beign set | ||
new_values : {} | ||
// New values that are being set | ||
new_values : {}, | ||
|
||
// Cached element getters | ||
cached_elements : new Map(), | ||
}; | ||
|
||
weak_properties.set(instance, map); | ||
} | ||
|
||
return map; | ||
} | ||
|
||
}; | ||
|
||
/** | ||
* Is the given name allowed as a property? | ||
|
@@ -884,7 +886,7 @@ Element.setStatic(function setAssignedProperty(name, getter, setter) { | |
* | ||
* @author Jelle De Loecker <[email protected]> | ||
* @since 2.0.0 | ||
* @version 2.1.0 | ||
* @version 2.3.19 | ||
* | ||
* @param {String|Object} name | ||
* @param {String} query | ||
|
@@ -901,15 +903,17 @@ Element.setStatic(function addElementGetter(name, query) { | |
return; | ||
} | ||
|
||
let symbol = Symbol(name); | ||
|
||
this.setProperty(name, function performQuery() { | ||
|
||
if (this[symbol] == null) { | ||
this[symbol] = this.querySelector(query); | ||
let private_map = getPrivate(this), | ||
result = private_map.cached_elements.get(name); | ||
|
||
if (result == null) { | ||
result = this.querySelector(query); | ||
private_map.cached_elements.set(name, result); | ||
} | ||
|
||
return this[symbol]; | ||
return result; | ||
}); | ||
}); | ||
|
||
|
@@ -918,7 +922,7 @@ Element.setStatic(function addElementGetter(name, query) { | |
* | ||
* @author Jelle De Loecker <[email protected]> | ||
* @since 2.0.0 | ||
* @version 2.1.0 | ||
* @version 2.3.19 | ||
*/ | ||
Element.setStatic(function addElementsGetter(name, query) { | ||
|
||
|
@@ -932,17 +936,18 @@ Element.setStatic(function addElementsGetter(name, query) { | |
return; | ||
} | ||
|
||
let symbol = Symbol(name); | ||
|
||
this.setProperty(name, function performQuery() { | ||
|
||
if (this[symbol] == null) { | ||
this[symbol] = this.querySelectorAll(query); | ||
let private_map = getPrivate(this), | ||
result = private_map.cached_elements.get(name); | ||
|
||
if (result == null) { | ||
result = this.querySelectorAll(query); | ||
private_map.cached_elements.set(name, result); | ||
} | ||
|
||
return this[symbol]; | ||
return result; | ||
}); | ||
|
||
}); | ||
|
||
/** | ||
|
@@ -973,6 +978,12 @@ function renderCustomTemplate(re_render) { | |
let template = this.inner_template, | ||
has_prepare_logic = typeof this.prepareRenderVariables == 'function'; | ||
|
||
// Get the private map | ||
let private_map = getPrivate(this); | ||
|
||
// And clear the element cache | ||
private_map.cached_elements.clear(); | ||
|
||
if (!template) { | ||
return this.prepareRenderVariables(); | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,4 +14,13 @@ var MySyncSpan = Blast.Bound.Function.inherits('Hawkejs.Element', 'MySyncSpan'); | |
* @since 0.1.0 | ||
* @version 0.1.0 | ||
*/ | ||
MySyncSpan.setTemplate('<span class="test">Test this sync template!</span>', true); | ||
MySyncSpan.setTemplate('<span class="test">Test this sync template!</span>', true); | ||
|
||
/** | ||
* Get the main span | ||
* | ||
* @author Jelle De Loecker <[email protected]> | ||
* @since 2.3.19 | ||
* @version 2.3.19 | ||
*/ | ||
MySyncSpan.addElementGetter('main_span', 'span.test'); |