2
2
3
3
// UrlState is a completely wrong hacky thing and should go away!
4
4
//
5
- // The correct method is:
5
+ // For now this here only is a step forward to separate the implementation from the use.
6
+ // On each DOM element, define
7
+ // data-urlstate="id"
8
+ // or
9
+ // data-urlstate
10
+ // which takes the element's id (fallback to name).
11
+ // On <input radio> you only need a single element.
12
+ //
13
+ // After that call
14
+ // UrlState.auto()
15
+ //
16
+ // DOM is not observed or live list, so elements showing up later are ignored.
17
+ // For those you must run
18
+ // state=UrlState.ADD(E(element))
19
+ // yourself.
20
+ //
21
+ // BLOBs like <textarea> are NOT supported with data-urlstate yet.
22
+ //
23
+ // Following elements are supported:
24
+ //
25
+ // <select> -> take checked <option> (id || option.$value || option.$text)
26
+ // <input text> -> the text
27
+ // <input radio> -> the checked one
28
+ // <input check> -> the check state
29
+
30
+ // The (future, not yet implemented) correct method is something like:
6
31
//
7
32
// - Define a special VALUE object which keeps a (possibly complex) value.
8
33
// - Best it is implemented as a Proxy with dictionary syntax.
60
85
// - These callbacks can inspect the value, alter it or even revoke the change
61
86
// - Revocation is done by throwing
62
87
// - Accept means return undefined (=== void 0)
63
- // - Changeing is done by returning something different
88
+ // - Changing is done by returning something different
64
89
//
65
90
// On top of that we then can implement VALUE-binding:
66
91
// - The VALUE then can be bound to a DOM element
77
102
// And on top of that we than can re-implement automatic UrlState.
78
103
// - We can then store big things like <textarea> into sessionstore/localstore/database as well
79
104
80
- // However: This all above is NOT the case today.
81
- // So this here is a step forward to separate the implementation from the use.
82
- // On each DOM element, define
83
- // data-urlstate="id"
84
- // or
85
- // data-urlstate
86
- // which takes the element's id (fallback to name).
87
- // On <input radio> you only need a single element.
88
- //
89
- // After that call UrlState.auto()
90
- //
91
- // DOM is not observed or live list, so elements showing up later are ignored.
92
- // For those you must run
93
- // state=UrlState.ADD(E(element))
94
- // yourself.
95
-
96
- // BLOBs like <textarea> are NOT supported with data-urlstate yet.
97
- //
98
- // Following elements are supported:
99
- //
100
- // <select> -> take checked <option> (id || option.$value || option.$text)
101
- // <input text> -> the text
102
- // <input radio> -> the checked one
103
- // <input check> -> the check state
104
-
105
105
Object . entries ( ( ( ) => {
106
106
107
107
function getset ( _ )
@@ -122,14 +122,16 @@ function getset(_)
122
122
case 'checkbox' : return { get :( ) => _ . checked , set :v => _ . checked = v } ;
123
123
124
124
default :
125
- console . warn ( 'UrlState: treating like text: INPUT type' , x . type , x ) ;
125
+ console . warn ( 'UrlState: treating like text: INPUT type' , _ . type , _ ) ;
126
+ case 'color' :
127
+ case 'number' :
126
128
case 'text' :
127
129
break ;
128
130
}
129
131
case 'SELECT' :
130
132
break ;
131
133
}
132
- return { get :( ) => _ . value , set :v => _ . value = v } ;
134
+ return { get :( ) => _ . value , set :v => console . log ( 'SET' , _ . type , _ . value = v ) } ;
133
135
}
134
136
135
137
const known = new Set ( ) ;
@@ -149,7 +151,7 @@ return (
149
151
150
152
// console.log('UrlState.ADD',id,e.$all,st);
151
153
if ( ! known . has ( e ) )
152
- e . ON ( 'change' , _ => { st . state = getset ( _ . target ) . get ( ) } ) ;
154
+ e . ON ( 'change _value ' , _ => { st . state = getset ( _ . target ) . get ( ) } ) ;
153
155
known . add ( e ) ;
154
156
return st ;
155
157
}
@@ -182,7 +184,7 @@ return (
182
184
}
183
185
184
186
// UrlState.auto(optionaldatasetname, optionalprefix)
185
- // datasetname defaults to
187
+ // optionaldatasetname defaults to
186
188
// urlstate
187
189
// giving data-urlstate for this here.
188
190
// optionalprefix defaults to
0 commit comments