Skip to content

Commit

Permalink
last v1.x.x version before revamp
Browse files Browse the repository at this point in the history
  • Loading branch information
PitPik committed Jan 5, 2023
1 parent 5ab8de6 commit a97e041
Show file tree
Hide file tree
Showing 14 changed files with 420 additions and 324 deletions.
9 changes: 4 additions & 5 deletions VOM.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ VOM.prototype = {
return crawlObject(item, property.split(pathSplit));
},
getCleanModel: function(item) { // maybe not...
return JSON.parse(JSON.stringify(item || this.model));
return JSON.parse(JSON.stringify(item || this.model));
},
destroy: function() {
return destroy(this, this.model);
Expand All @@ -137,7 +137,7 @@ function findProperty(node, id, prop, val, result, isFn, hasVal, hasProp, keys)
node[id][prop] : crawlObject(node[id], (keys[0] ?
keys : (keys = hasProp && prop.split(pathSplit))));

if ((hasVal && propValue === val || (isFn && val(propValue))) ||
if ((hasVal && propValue === val || (isFn && val(propValue, node[id]))) ||
(!hasVal && undefined !== propValue) ||
(!hasVal && !hasProp)) {
result.push(node[id]);
Expand All @@ -158,7 +158,7 @@ function destroy(_this, items) { // only cleans up NODES
destroy(_this, items[n][_this.options.childNodes]);
}
delete NODES[_this.id][items[n][_this.options.idProperty]];
items.pop();
// items.pop(); // no, keep for looping through childNodes later on
}
return items;
};
Expand Down Expand Up @@ -316,8 +316,7 @@ function defineProperty(_this, prop, obj, cache, enumable, path) {
return prop === 'index' ? indexOf(_this, obj.current) : cache[prop];
},
set: function(value) {
validate((path || prop), obj, cache[prop],
cache[prop] = value, cache, _this);
validate((path || prop), obj, cache[prop], cache[prop] = value, cache, _this);
},
enumerable: enumable
});
Expand Down
26 changes: 15 additions & 11 deletions amd.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/**! @license amd v0.1.0; Copyright (C) 2019 by Peter Dematté */
/**! @license amd v0.1.1; Copyright (C) 2021 by Peter Dematté */
!(function (root) { 'use strict';

var mathRand = root.Math.random;
Expand All @@ -8,6 +8,8 @@ var timer = 0;
var modules = require.modules = {};
var executedModule = {};

if (root.define && root.define.amd) return;

define.amd = {};
require.config = config;
require.getFile = function(resource, markAsDone) { return resource; };
Expand All @@ -29,7 +31,7 @@ function getPathFromName(name) {
var postFix = /(?:^\!|^http[s]*:|.*\.js$)/.test(name) ? '' : '.js';
var path = '';

name = (require.paths[name] || name).replace(/^\!/, '');
name = (require.paths[name] || name).replace(/^[!%]/, '');
path = normalizePath((require.baseUrl || '.') + '/' +
name + postFix).replace(/^.\//, '');
return require.mapPath ? require.mapPath(name, postFix, path) : path;
Expand Down Expand Up @@ -102,13 +104,13 @@ function markAsDone(module) {
}
}

function appendScript(script) {
documentFragment.appendChild(script);
clearTimeout(timer);
timer = setTimeout(function() {
document.head.appendChild(documentFragment);
});
}
// function appendScript(script) {
// documentFragment.appendChild(script);
// clearTimeout(timer);
// timer = setTimeout(function() {
// document.head.appendChild(documentFragment);
// });
// }

function applyScript(module, sync) {
var script = root.document.createElement('script');
Expand Down Expand Up @@ -149,7 +151,7 @@ function onScriptLoaded(module) {
}

function getDependencies(parentName, deps, sync) {
for (var n = deps.length, module = {}, name = ''; n --; ) {
for (var n = deps.length, module = {}, name = ''; n--; ) {
name = deps[n];
if (modules[name]) {
modules[name].parents.push(parentName);
Expand All @@ -165,10 +167,12 @@ function getDependencies(parentName, deps, sync) {
if (module.isFile) {
require.getFile(module, markAsDone);
} else if (!module.isInline) {
appendScript(applyScript(module, sync));
// appendScript(applyScript(module, sync));
documentFragment.appendChild(applyScript(module, sync));
lookaheadForDeps(name);
}
}
if (documentFragment.childNodes.length) document.head.appendChild(documentFragment);
}

function require(deps, factory, sync) {
Expand Down
14 changes: 10 additions & 4 deletions api.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ prototype.publish = function(inst, comp, attr, data) {
comp[attr].value = data;
comp[attr][0] && publish(this, comp[attr], data);
}
return data;
};

prototype.unsubscribe = function(inst, comp, attr, callback) {
Expand Down Expand Up @@ -239,16 +240,20 @@ prototype.renderModule = function(data) {

if (!isValid) {
if (data.scroll && container.children) {
container.children[0]._scroll = (Toolbox.$(data.scroll, container) || {}).scrollTop;
container.children[0]._scroll =
(Toolbox.$(data.scroll, container) || {}).scrollTop;
}
return new Promise(function(){});
}

if (item) {
return new Toolbox.Promise(function(resolve) {
appendChildToContainer(item.element, container, data);
if (item.instance && item.instance.onLoad) item.instance.onLoad(item.element, _this);
if (item.instance && item.instance.onRender) item.instance.onRender(data.data);
// TODO: data.parent -> input doesn't work...
if (item.instance && item.instance.onLoad)
item.instance.onLoad(item.element, _this, data.parent);
if (item.instance && item.instance.onRender)
item.instance.onRender(data.data);
resolve(item);
});
}
Expand All @@ -264,7 +269,8 @@ prototype.renderModule = function(data) {
var item = module.instance || instance;

appendChildToContainer(componentElm, container, data);
if (item && item.onLoad) item.onLoad(componentElm, _this);
// TODO: data.parent -> input doesn't work...
if (item && item.onLoad) item.onLoad(componentElm, _this, data.parent);
if (item && item.onRender) item.onRender(data.data);
resolve(modulesMap[(data.context || '') + data.require] = !module.instance ? {
element: componentElm,
Expand Down
Loading

0 comments on commit a97e041

Please sign in to comment.