Skip to content

Commit

Permalink
v1.3.0
Browse files Browse the repository at this point in the history
  • Loading branch information
worldoptimizer authored Sep 26, 2023
1 parent 2fd0457 commit b47e027
Showing 1 changed file with 37 additions and 6 deletions.
43 changes: 37 additions & 6 deletions HypeReactiveContent.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*!
Hype Reactive Content 1.2.2
Hype Reactive Content 1.3.0
copyright (c) 2022 Max Ziebell, (https://maxziebell.de). MIT-license
*/
/*
Expand Down Expand Up @@ -40,16 +40,19 @@ copyright (c) 2022 Max Ziebell, (https://maxziebell.de). MIT-license
* 1.2.1 Added hypeDocument.customDataUpdate on Hype document basis
* Fixed minor misses in the IDE highlighting for effect
* 1.2.2 Tweaked color highlighting in the IDE to color unscoped items in scopes correctly
* 1.3.0 Added WeakMap setter for hypeDocument.customData to automatically apply reactivity on reassignments
*/
if("HypeReactiveContent" in window === false) window['HypeReactiveContent'] = (function () {

/* @const */
const _isHypeIDE = window.location.href.indexOf("/Hype/Scratch/HypeScratch.") != -1;
const customDataMap = new WeakMap();

_default = {
scopeSymbol: '⇢',
visibilitySymbol: '👁️',
effectSymbol: '⚡️',
debounceCustomDataUpdate: true,
}

if (_isHypeIDE) {
Expand Down Expand Up @@ -203,7 +206,7 @@ if("HypeReactiveContent" in window === false) window['HypeReactiveContent'] = (f
});

} else {

try {
let $context = new Proxy(Object.assign({
element: options.element,
Expand Down Expand Up @@ -272,7 +275,32 @@ if("HypeReactiveContent" in window === false) window['HypeReactiveContent'] = (f
scope: scope
};
}


/**
* Function to setup the customData proxy on the hypeDocument
*
* @param {HYPE.documents.API} hypeDocument - the hypeDocument
*/
function setupCustomDataProxy(hypeDocument) {
let currentCustomData = hypeDocument.customData || {};
customDataMap.set(hypeDocument, currentCustomData);

Object.defineProperty(hypeDocument, 'customData', {
get: function() {
return customDataMap.get(hypeDocument);
},
set: function(newValue) {
const reactiveData = enableReactiveObject(newValue, hypeDocument.refreshReactiveContentDebounced);
customDataMap.set(hypeDocument, reactiveData);
if(getDefault('debounceCustomDataUpdate')) {
hypeDocument.refreshReactiveContentDebounced();
} else {
hypeDocument.refreshReactiveContent();
}
}
});
}

/**
* @function HypeDocumentLoad
* @param {object} hypeDocument - the hypeDocument
Expand All @@ -281,6 +309,7 @@ if("HypeReactiveContent" in window === false) window['HypeReactiveContent'] = (f
*/
function HypeDocumentLoad(hypeDocument, element, event) {


let behaviorCallbacks = {}
function behaviorActionHelper(elm, type, datasetKey, action, behavior){
let bubbleElm = elm.closest('['+datasetKey+'-action]');
Expand Down Expand Up @@ -370,10 +399,12 @@ if("HypeReactiveContent" in window === false) window['HypeReactiveContent'] = (f
}

hypeDocument.enableReactiveCustomData = function(data){
hypeDocument.customData = Object.assign(hypeDocument.customData, data || {});
hypeDocument.customData = enableReactiveObject(hypeDocument.customData, hypeDocument.refreshReactiveContentDebounced);
const existingData = customDataMap.get(hypeDocument) || {};
hypeDocument.customData = Object.assign(existingData, data || {});
}

setupCustomDataProxy(hypeDocument);

hypeDocument.enableReactiveCustomData(getDefault('customData') || {})

if (hypeDocument.functions().HypeReactiveContent) hypeDocument.functions().HypeReactiveContent(hypeDocument, element, event);
Expand Down Expand Up @@ -451,7 +482,7 @@ if("HypeReactiveContent" in window === false) window['HypeReactiveContent'] = (f
}

return {
version: '1.2.2',
version: '1.3.0',
setDefault: setDefault,
getDefault: getDefault,
enableReactiveObject: enableReactiveObject,
Expand Down

0 comments on commit b47e027

Please sign in to comment.