Add filter layer

This commit is contained in:
Abdussamed 2023-06-18 16:10:05 +03:00
parent 13b2ac413f
commit 5ad3c17235
3 changed files with 54 additions and 2342 deletions

2302
data.json

File diff suppressed because it is too large Load Diff

View File

@ -1,21 +0,0 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<script src="./wire.js"></script>
<script>
let yup = é([]);
fetch("data.json")
.then(e => e.json())
.then(kkk => {
debugger;
yup.set(kkk);
});
</script>
</body>
</html>

71
wire.js
View File

@ -8,21 +8,50 @@
0x20 32 immediate change
*/
(()=>{
let pipeLine = function(){
let pipeLine = function(wire){
let _caches = {};
let _cache_version = null;
this.reads = [];
this.writes = [];
this.read = (fn,pr) => reads.push({fn,pr});
this.write = (fn,pr) => writes.push({fn,pr});
this.get = (val) => {
let fns = reads.sort((a,b) => (a?.pr|0) - (b?.pr|0)),
real = val;
this.filters = new Map();
this.read = (fn,pr) => this.reads.push({fn,pr});
this.write = (fn,pr) => this.writes.push({fn,pr});
this.filter = (name, fn) => this.filters.set(name,fn);
this.get = (val,filters = []) => {
let real = val;
if(filters.length)
{
if(_cache_version !== wire.version())
{
_caches = {};
};
for (const name of filters)
{
if(_caches[name])
{
real = _caches[name];
continue;
}
let func = this.filters.get(name);
if(func)
{
func(real, e => {
real = e;
_caches[name] = e;
});
}
};
_cache_version = wire.version();
};
let fns = this.reads.sort((a,b) => (a?.pr|0) - (b?.pr|0));
for (const { fn } of fns) {
fn( real, e => real = e );
};
return real;
};
this.set = () => {
let fns = writes.sort((a,b) => (a?.pr|0) - (b?.pr|0)),
let fns = this.writes.sort((a,b) => (a?.pr|0) - (b?.pr|0)),
real = val;
for (const { fn } of fns) {
fn( real, e => real = e );
@ -57,9 +86,9 @@
if(this instanceof é)
{
this.value = é.extract(defaultValue);
this.version = 0;
this._version = 0;
this.effects = [];
this.piping = new pipeLine();
this.piping = new pipeLine(this);
this.flag = 8;
}else{
return new é(defaultValue)
@ -211,10 +240,10 @@
é.prototype.fp = é.fingerPrint;
é.prototype.diff = é.diff;
é.prototype.get = function(){
é.prototype.get = function(...filters){
if(this.flag & 2)
{
return this.piping.get(this.value)
return this.piping.get(this.value,filters)
}else{
return this.value
}
@ -239,7 +268,7 @@
}));
}
this.value = newValue;
this.version++;
this._version++;
if(this.flag & 1)
{
schedule((()=>{
@ -278,20 +307,26 @@
})
this.effects.push(k);
};
é.prototype.getVersion = function(){
return this.version;
é.prototype.version = function(){
return this._version;
}
é.prototype.equalTo = function(value){
return é.isSame(value, this.value)
}
é.prototype.readLayer = function(value){
é.prototype.read = function(argument1, argument2, argument3){
this.flag = this.flag | 2;
this.piping.read(a,b)
if(typeof argument1=="string")
{
this.piping.filter(argument1, argument2, argument3);
}else{
this.piping.read(argument1, argument2)
}
}
é.prototype.writeLayer = function(value){
é.prototype.write = function(value, pr){
this.flag = this.flag | 4;
this.piping.write(a,b)
this.piping.write(value, pr)
}
try{
module.exports = é;
}catch{