Skip to content

Commit 6bdcefb

Browse files
author
Michael Solomon
committed
Finel the prototype - send to Itzik for review
1 parent 7302f5e commit 6bdcefb

7 files changed

+167
-212
lines changed

Cookie.hxproj

+1
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
<!-- Class files to compile (other referenced classes will automatically be included) -->
3434
<compileTargets>
3535
<compile path="src\Main.hx" />
36+
<compile path="src\CookiesT.hx" />
3637
</compileTargets>
3738
<!-- Paths to exclude from the Project Explorer tree -->
3839
<hiddenPaths>

SampleAbstract.hx

+53
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
package;
2+
3+
/**
4+
* ...
5+
* @author Michael
6+
*/
7+
class SampleAbstract
8+
{
9+
var cookies;
10+
public function new() {
11+
cookies = new SimpleCookie();
12+
Cookie.set("complex", "a=b,b=c");
13+
var cookiesMap:StringMap<String> = Cookie.all();
14+
for (name in cookiesMap.keys()) {
15+
var subValues:Array<String> = cookiesMap.get(name).split(",");
16+
if (subValues.length > 1) {
17+
cookies[name] = { };
18+
for (pair in subValues) {
19+
cookies[name][pair.split("=")[0]] = pair.split("=")[1];
20+
}
21+
}else {
22+
cookies[name] = subValues[0];
23+
}
24+
}
25+
}
26+
}
27+
28+
class SubCookie {
29+
public function new() {}
30+
@:keep public function toString()
31+
return haxe.Json.stringify(this);
32+
}
33+
34+
abstract SimpleCookie(Dynamic) to Dynamic {
35+
public inline function new() this = new SubCookie();
36+
@:arrayAccess function get(key:String):SimpleCookie {
37+
if (!Reflect.hasField(this, key))
38+
Reflect.setField(this, key, new SubCookie());
39+
return Reflect.field(this, key);
40+
}
41+
@:arrayAccess function setString(key:String, value:String):String {
42+
Reflect.setField(this, key, value);
43+
return value;
44+
}
45+
46+
@:arrayAccess function setDynamic(key:String, value:Dynamic):Dynamic {
47+
Reflect.setField(this, key, value);
48+
return value;
49+
}
50+
51+
public inline function keys()
52+
return Reflect.fields(this);
53+
}

bin/Cookie.js

+49-163
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

bin/Cookie.js.map

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

bin/index.html

+5-2
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,11 @@
88
<body>
99
<script src="Cookie.js"></script>
1010
<script>
11-
var cookies = Cookies.cookies;
12-
Cookies.set("complex","a","1");
11+
//var cookies = Cookies.cookies;
12+
//cookies.a.b = 1;
13+
cookie = Cookies.prototype
14+
console.log(cookie.get("simple"));
15+
console.log(cookie.get("complex","b"));
1316
</script>
1417
</body>
1518
</html>

0 commit comments

Comments
 (0)