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