1- import MasterExamples from './MasterExamples.js' ;
1+ /* global __ */
2+ import MasterExamples from './MasterExamples.js'
23// used for examples
3- import { ProxifyHook } from '../../JavaScript/Classes/Helper/ProxifyHook.js' ;
4- import { Chain } from '../../JavaScript/Classes/Traps/Misc/Chain.js' ;
4+ import { ProxifyHook } from '../../JavaScript/Classes/Helper/ProxifyHook.js'
5+ import { Chain } from '../../JavaScript/Classes/Traps/Misc/Chain.js'
56
67export default class ChainDocs extends MasterExamples {
7- constructor ( makeGlobal ) {
8- super ( makeGlobal ) ;
9- this . name = 'chainDocs' ;
10- return this . html ( __ ( 'div' ) , ...this . text ( ) ) ;
11- }
12- text ( ) {
13- return [
14- 'Chain' ,
15- `The trap called Chain at /JavaScript/Classes/Traps/Misc/Chain.js, does Method Chaining. The $get and $set allow
8+ constructor ( makeGlobal ) {
9+ super ( makeGlobal )
10+ this . name = 'chainDocs'
11+ return this . html ( __ ( 'div' ) , ...this . text ( ) )
12+ }
13+ text ( ) {
14+ return [
15+ 'Chain' ,
16+ `The trap called Chain at /JavaScript/Classes/Traps/Misc/Chain.js, does Method Chaining. The $get and $set allow
1617 accessing properties as a function statement. $func makes it easy to execute any function within the method chaining and $_ can be prepended
1718 to any function name on the target object, to have it return the Proxy itself and for that doesn't break the chain.` ,
18- `$get + "propName"(func = undefined, ...args = undefined);
19+ `$get + "propName"(func = undefined, ...args = undefined);
1920 <ul>
2021 <li>[func]: function = a callback, which receives: receiver, prop, receiver[prop] (the value of the property), ...args.</li>
2122 <li>[...args]: any = arguments which will be passed to the function.</li>
@@ -37,97 +38,97 @@ export default class ChainDocs extends MasterExamples {
3738 <li>[...args]: any = arguments which will be passed to the function.</li>
3839 </ul>
3940 => returns the Proxy` ,
40- `import { ProxifyHook } from './JavaScript/Classes/Helper/ProxifyHook.js;<br>
41+ `import { ProxifyHook } from './JavaScript/Classes/Helper/ProxifyHook.js;<br>
4142 import { Chain } from './JavaScript/Classes/Traps/Misc/Chain.js';<br><br>` ,
42- 'Example without comments' ,
43- this . example1 ,
44- `Please, open the console in your developer tools and play with chainState!` ,
45- 'Example with comments' ,
46- this . example2 ,
47- `Please, open the console in your developer tools and play with chainState!`
48- ] ;
49- }
50- example1 ( receiver ) {
51- // assemble the ProxifyHook with the minimum traps required
52- const inject = new ProxifyHook ( Chain ( ) ) . get ( ) ;
53-
54- // proxify body
55- const body = inject ( receiver ) ;
56-
57- // proxify the object to which the Chain shall be applied
58- this . makeGlobal ( 'chainState' , inject ( {
59- a : 'Hello World!' ,
60- b : 'Hello Universe!' ,
61- c : function ( str ) {
62- this . b = str ;
63- return str ;
64- }
65- } ) ) . $getA ( ( receiver , prop , value , ...args ) => {
66- body . appendChild ( inject ( 'p' ) ) . $setInnerHTML ( `${ value } :${ args [ 0 ] } ` ) ;
67- } , 'My Argument' )
68- . $func ( ( receiver , ...args ) => {
69- body . appendChild ( inject ( 'b' ) ) . $setInnerHTML ( receiver . a ) . parentElement . appendChild ( inject ( 'b' ) ) . $setInnerHTML ( receiver . b ) ;
70- } )
71- . $setB ( 'Hello Galaxy!' )
72- . $getB ( ( receiver , prop , value , ...args ) => {
73- body . appendChild ( inject ( 'p' ) ) . $setInnerHTML ( `${ value } ` ) ;
74- } )
75- . $_c ( 'Hello SpaceX!' )
76- . $getB ( ( receiver , prop , value , ...args ) => {
77- body . appendChild ( inject ( 'p' ) ) . $setInnerHTML ( `${ value } ` ) ;
78- } ) ;
79- }
80- example2 ( receiver ) {
81- // assemble the ProxifyHook with the minimum traps required
82- const inject = new ProxifyHook ( Chain ( ) ) . get ( ) ;
83-
84- // proxify body
85- const body = inject ( receiver ) ;
86-
87- // proxify the object to which the Chain shall be applied
88- this . makeGlobal ( 'chainState' , inject ( {
89- a : 'Hello World!' ,
90- b : 'Hello Universe!' ,
91- c : function ( str ) {
92- this . b = str ;
93- return str ;
94- }
95- } ) )
96- // getTrapGet: get an object property and hand it over to custom callback. Returns Proxy.
97- . $getA ( ( receiver , prop , value , ...args ) => {
98- // append p to body
99- body . appendChild ( inject ( 'p' ) )
100- // getTrapSet: set an object property. Returns Proxy.
101- . $setInnerHTML ( `${ value } :${ args [ 0 ] } ` ) ; // "Hello World!:My Argument"
102- } , 'My Argument' )
103- // getTrapFunc: hands over the receiver to a custom function. Returns Proxy.
104- . $func ( ( receiver , ...args ) => {
105- // append p to body
106- body . appendChild ( inject ( 'b' ) )
107- // getTrapSet: set an object property. Returns Proxy.
108- . $setInnerHTML ( receiver . a ) ; // "Hello World!"
109- // append p to body
110- body . appendChild ( inject ( 'b' ) )
111- // getTrapSet: set an object property. Returns Proxy.
112- . $setInnerHTML ( receiver . b ) ; // "Hello Universe!"
113- } )
43+ 'Example without comments' ,
44+ this . example1 ,
45+ `Please, open the console in your developer tools and play with chainState!` ,
46+ 'Example with comments' ,
47+ this . example2 ,
48+ `Please, open the console in your developer tools and play with chainState!`
49+ ]
50+ }
51+ example1 ( receiver ) {
52+ // assemble the ProxifyHook with the minimum traps required
53+ const inject = new ProxifyHook ( Chain ( ) ) . get ( )
54+
55+ // proxify body
56+ const body = inject ( receiver )
57+
58+ // proxify the object to which the Chain shall be applied
59+ this . makeGlobal ( 'chainState' , inject ( {
60+ a : 'Hello World!' ,
61+ b : 'Hello Universe!' ,
62+ c : function ( str ) {
63+ this . b = str
64+ return str
65+ }
66+ } ) ) . $getA ( ( receiver , prop , value , ...args ) => {
67+ body . appendChild ( inject ( 'p' ) ) . $setInnerHTML ( `${ value } :${ args [ 0 ] } ` )
68+ } , 'My Argument' )
69+ . $func ( ( receiver , ...args ) => {
70+ body . appendChild ( inject ( 'b' ) ) . $setInnerHTML ( receiver . a ) . parentElement . appendChild ( inject ( 'b' ) ) . $setInnerHTML ( receiver . b )
71+ } )
72+ . $setB ( 'Hello Galaxy!' )
73+ . $getB ( ( receiver , prop , value , ...args ) => {
74+ body . appendChild ( inject ( 'p' ) ) . $setInnerHTML ( `${ value } ` )
75+ } )
76+ . $_c ( 'Hello SpaceX!' )
77+ . $getB ( ( receiver , prop , value , ...args ) => {
78+ body . appendChild ( inject ( 'p' ) ) . $setInnerHTML ( `${ value } ` )
79+ } )
80+ }
81+ example2 ( receiver ) {
82+ // assemble the ProxifyHook with the minimum traps required
83+ const inject = new ProxifyHook ( Chain ( ) ) . get ( )
84+
85+ // proxify body
86+ const body = inject ( receiver )
87+
88+ // proxify the object to which the Chain shall be applied
89+ this . makeGlobal ( 'chainState' , inject ( {
90+ a : 'Hello World!' ,
91+ b : 'Hello Universe!' ,
92+ c : function ( str ) {
93+ this . b = str
94+ return str
95+ }
96+ } ) )
97+ // getTrapGet: get an object property and hand it over to custom callback. Returns Proxy.
98+ . $getA ( ( receiver , prop , value , ...args ) => {
99+ // append p to body
100+ body . appendChild ( inject ( 'p' ) )
101+ // getTrapSet: set an object property. Returns Proxy.
102+ . $setInnerHTML ( `${ value } :${ args [ 0 ] } ` ) // "Hello World!:My Argument"
103+ } , 'My Argument' )
104+ // getTrapFunc: hands over the receiver to a custom function. Returns Proxy.
105+ . $func ( ( receiver , ...args ) => {
106+ // append p to body
107+ body . appendChild ( inject ( 'b' ) )
108+ // getTrapSet: set an object property. Returns Proxy.
109+ . $setInnerHTML ( receiver . a ) // "Hello World!"
110+ // append p to body
111+ body . appendChild ( inject ( 'b' ) )
112+ // getTrapSet: set an object property. Returns Proxy.
113+ . $setInnerHTML ( receiver . b ) // "Hello Universe!"
114+ } )
115+ // getTrapSet: set an object property. Returns Proxy.
116+ . $setB ( 'Hello Galaxy!' )
117+ // getTrapGet: get an object property and hand it over to custom callback. Returns Proxy.
118+ . $getB ( ( receiver , prop , value , ...args ) => {
119+ // append p to body
120+ body . appendChild ( inject ( 'p' ) )
121+ // getTrapSet: set an object property. Returns Proxy.
122+ . $setInnerHTML ( `${ value } ` ) // "Hello Galaxy!"
123+ } )
124+ // getTrap_ (underscore): executes a function on the object. Returns Proxy and ignores the functions return.
125+ . $_c ( 'Hello SpaceX!' )
126+ // getTrapGet: get an object property and hand it over to custom callback. Returns Proxy.
127+ . $getB ( ( receiver , prop , value , ...args ) => {
128+ // append p to body
129+ body . appendChild ( inject ( 'p' ) )
114130 // getTrapSet: set an object property. Returns Proxy.
115- . $setB ( 'Hello Galaxy!' )
116- // getTrapGet: get an object property and hand it over to custom callback. Returns Proxy.
117- . $getB ( ( receiver , prop , value , ...args ) => {
118- // append p to body
119- body . appendChild ( inject ( 'p' ) )
120- // getTrapSet: set an object property. Returns Proxy.
121- . $setInnerHTML ( `${ value } ` ) ; // "Hello Galaxy!"
122- } )
123- // getTrap_ (underscore): executes a function on the object. Returns Proxy and ignores the functions return.
124- . $_c ( 'Hello SpaceX!' )
125- // getTrapGet: get an object property and hand it over to custom callback. Returns Proxy.
126- . $getB ( ( receiver , prop , value , ...args ) => {
127- // append p to body
128- body . appendChild ( inject ( 'p' ) )
129- // getTrapSet: set an object property. Returns Proxy.
130- . $setInnerHTML ( `${ value } ` ) ; // "Hello SpaceX!"
131- } ) ;
132- }
133- }
131+ . $setInnerHTML ( `${ value } ` ) // "Hello SpaceX!"
132+ } )
133+ }
134+ }
0 commit comments