Browse Source

auto commit

app
jfinn 3 years ago
parent
commit
9c0d4d4753
1 changed files with 188 additions and 1 deletions
  1. 188
    1
      mdev/dev_sto.native.js

+ 188
- 1
mdev/dev_sto.native.js View File

@@ -77,6 +77,35 @@ function type_info(o){
77 77
 	}
78 78
 	// clog(t,flags)
79 79
 }
80
+function deep_prop_v0(o,p){
81
+	try {
82
+	var arr = jc(p)
83
+	var ret = o
84
+
85
+	while (arr.length){
86
+		// clog("deep_prop",arr,ret)
87
+		ret = ret[arr.shift()]
88
+	}
89
+	// clog("deep_prop ret",ret)
90
+	return ret
91
+	} catch(err){console.error("DEEP_PROP ERR:",err)}
92
+}
93
+
94
+
95
+
96
+
97
+
98
+
99
+
100
+
101
+
102
+
103
+
104
+
105
+
106
+
107
+
108
+
80 109
 
81 110
 
82 111
 
@@ -409,7 +438,165 @@ var permissions_def = {
409 438
 	}
410 439
 
411 440
 
441
+
442
+function splice_out(arr,elm){
443
+	let i = arr.indexOf(elm)
444
+	// var r = "" 
445
+	if (i != -1){
446
+		return arr.splice(i,1)
447
+	}
448
+	// return
449
+
450
+}
451
+function gen_sort_attr(attr){
452
+	return function gsort(a0,a1){
453
+
454
+	// clog("z",a0,a1)
455
+	if (a0[attr] > a1[attr]){
456
+	return 1
457
+
458
+	} else if (a0[attr] < a1[attr]){
459
+	return -1
460
+
461
+	} else {
462
+	return 0
463
+
464
+	}
465
+	}
466
+}
467
+
468
+
469
+
470
+
471
+
472
+var dflt_opts = {
473
+	sort_fn:gen_sort_attr("override_level"),
474
+	log_level:0,
475
+	// ns:"",
476
+}
477
+class BoundObj{
478
+	constructor(){
479
+		this.init()
480
+	}
481
+
482
+    init(){
483
+        let k,v,i,j
484
+        for ([k,v] of Object.entries(Object.getOwnPropertyDescriptors(this.__proto__))){
485
+            if (k.endsWith("_ub") && typeof(v.value) == "function"){
486
+                // clog("UB",k,k.slice(1,-3))
487
+                j = v.value.bind(this)
488
+                j.meta_str = "bound_fn"
489
+                this[k.slice(1,-3)] = j
490
+            }
491
+        }
492
+        
493
+
494
+    }
495
+    /*
496
+	mx2_ub(){
497
+		clog("Mx2")
498
+	}
499
+    */
500
+
501
+
502
+}
503
+
504
+// class reg_cb_ord{
505
+class reg_cb_ord extends BoundObj{
506
+	// con
507
+	constructor(opts){
508
+		super()
509
+		this.opts = Object.assign({},dflt_opts,opts)
510
+		this.r = Object.assign(this,dflt_opts,opts)
511
+		// this.sort_fn = this.opts
512
+
513
+		this.cb_sto = {}
514
+		this._orig_opts = opts
515
+		clog("v2 ",this)
516
+	}
517
+	_reg_cb_ub(cb,key_name,cb_name,override_level = 100,push=1){
518
+
519
+		if (typeof(cb) != "function"){
520
+			console.error("callback is not a function. setting push=r","\ncb:",cb)
521
+			push = "r"
522
+			// console.error("callback:",cb," is not a function")
523
+		}
524
+		// var this.cb_sto = {}
525
+		var cb_sort = nop
526
+	
527
+		if (!this.cb_sto[key_name]){
528
+			this.cb_sto[key_name] = []
529
+		}
530
+		// this.cb_sto[key_name].find(find_html_cb,{fn_key:cb_name})
531
+		// splice_out_ti(this.cb_sto[key_name],this.cb_sto[key_name].find(find_html_cb,{fn_key:cb_name}))
532
+		// var cbo0= this.cb_sto[key_name].find(glob_td.fn.find_html_cb,{fn_key:cb_name})
533
+		// var cbo0= this.cb_sto[key_name].find(find_attr,{fn_key:cb_name})
534
+		var cbo0= this.cb_sto[key_name].find(find_attr,{attr:"fn_key",val:cb_name})
535
+		// clog(cbo0)
536
+		splice_out(this.cb_sto[key_name],cbo0)
537
+		// tn2t.arr.
538
+	
539
+		// splice_out_cb
540
+		let cb_obj = {
541
+			cb,
542
+			hkey:key_name,
543
+			fn_key:cb_name,
544
+			override_level,
545
+		}
546
+		if (push=="r"){
547
+	
548
+		} else if (push){
549
+			this.cb_sto[key_name].push(cb_obj)
550
+		} else {
551
+			this.cb_sto[key_name].unshift(cb_obj)
552
+		}
553
+		this.cb_sto[key_name].sort(this.sort_fn)
554
+
555
+
556
+	}
557
+	_run_cbs_ub(key,arg_obj){
558
+	
559
+		var k,v
560
+		var o = {
561
+			// html_key:key,cbs:glob_mx.html_cb[key],
562
+		}
563
+	
564
+			// dlog("RUN_HOOK_CB??",key,glob_mx.hook_cb[key])
565
+		try {
566
+	
567
+			this.opts.log_level  ? clog("run_cbs",arg_obj,o,{that:this,hkey:key,cbs:this.cb_sto[key]}) : 0
568
+	
569
+	
570
+		for ([k,v] of Object.entries(this.cb_sto[key]|| {}) ) {
571
+			// dlog("RUN_HOOK_CB:",k)
572
+			// clog("run_html_cbs:",k,v)
573
+
574
+			this.opts.log_level > 1 ? clog("run_cbs_e",arg_obj,o,{that:this,hkey:key,cbs:this.cb_sto[key],k,v}) : 0
575
+			v.cb(arg_obj,o,{that:this,hkey:key,cbs:this.cb_sto[key],k,v})
576
+			// v(o)
577
+		}
578
+		} catch(err){
579
+			console.error("ti_v_cb err:",err)
580
+		}
581
+
582
+	}
583
+/*	fn1(){
584
+		clog("fn1",{that:this,args:[...arguments]})
585
+	}*/
586
+}
587
+
588
+
589
+
590
+
591
+
592
+
593
+
594
+
595
+
596
+
597
+
598
+
412 599
 window.tmp_dev_sto = {
413
-	Proxy_Factory,Proxy_Permissions
600
+	Proxy_Factory,Proxy_Permissions,reg_cb_ord,BoundObj
414 601
 }
415 602
 // Proxy_Factory

Loading…
Cancel
Save