Skip to content

Commit 3850f12

Browse files
committed
urlstate.js modified
1 parent 5b477f0 commit 3850f12

File tree

1 file changed

+33
-31
lines changed

1 file changed

+33
-31
lines changed

urlstate.js

Lines changed: 33 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,32 @@
22

33
// UrlState is a completely wrong hacky thing and should go away!
44
//
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:
631
//
732
// - Define a special VALUE object which keeps a (possibly complex) value.
833
// - Best it is implemented as a Proxy with dictionary syntax.
@@ -60,7 +85,7 @@
6085
// - These callbacks can inspect the value, alter it or even revoke the change
6186
// - Revocation is done by throwing
6287
// - Accept means return undefined (=== void 0)
63-
// - Changeing is done by returning something different
88+
// - Changing is done by returning something different
6489
//
6590
// On top of that we then can implement VALUE-binding:
6691
// - The VALUE then can be bound to a DOM element
@@ -77,31 +102,6 @@
77102
// And on top of that we than can re-implement automatic UrlState.
78103
// - We can then store big things like <textarea> into sessionstore/localstore/database as well
79104

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-
105105
Object.entries((()=>{
106106

107107
function getset(_)
@@ -122,14 +122,16 @@ function getset(_)
122122
case 'checkbox': return { get:()=>_.checked, set:v=>_.checked=v };
123123

124124
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':
126128
case 'text':
127129
break;
128130
}
129131
case 'SELECT':
130132
break;
131133
}
132-
return { get:() => _.value, set:v => _.value=v };
134+
return { get:() => _.value, set:v => console.log('SET', _.type, _.value=v) };
133135
}
134136

135137
const known = new Set();
@@ -149,7 +151,7 @@ return (
149151

150152
// console.log('UrlState.ADD',id,e.$all,st);
151153
if (!known.has(e))
152-
e.ON('change', _ => { st.state = getset(_.target).get() });
154+
e.ON('change _value', _ => { st.state = getset(_.target).get() });
153155
known.add(e);
154156
return st;
155157
}
@@ -182,7 +184,7 @@ return (
182184
}
183185

184186
// UrlState.auto(optionaldatasetname, optionalprefix)
185-
// datasetname defaults to
187+
// optionaldatasetname defaults to
186188
// urlstate
187189
// giving data-urlstate for this here.
188190
// optionalprefix defaults to

0 commit comments

Comments
 (0)