Skip to content

Commit

Permalink
Finel the prototype - send to Itzik for review
Browse files Browse the repository at this point in the history
  • Loading branch information
Michael Solomon committed Jun 24, 2015
1 parent 7302f5e commit 6bdcefb
Show file tree
Hide file tree
Showing 7 changed files with 167 additions and 212 deletions.
1 change: 1 addition & 0 deletions Cookie.hxproj
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
<!-- Class files to compile (other referenced classes will automatically be included) -->
<compileTargets>
<compile path="src\Main.hx" />
<compile path="src\CookiesT.hx" />
</compileTargets>
<!-- Paths to exclude from the Project Explorer tree -->
<hiddenPaths>
Expand Down
53 changes: 53 additions & 0 deletions SampleAbstract.hx
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package;

/**
* ...
* @author Michael
*/
class SampleAbstract
{
var cookies;
public function new() {
cookies = new SimpleCookie();
Cookie.set("complex", "a=b,b=c");
var cookiesMap:StringMap<String> = Cookie.all();
for (name in cookiesMap.keys()) {
var subValues:Array<String> = cookiesMap.get(name).split(",");
if (subValues.length > 1) {
cookies[name] = { };
for (pair in subValues) {
cookies[name][pair.split("=")[0]] = pair.split("=")[1];
}
}else {
cookies[name] = subValues[0];
}
}
}
}

class SubCookie {
public function new() {}
@:keep public function toString()
return haxe.Json.stringify(this);
}

abstract SimpleCookie(Dynamic) to Dynamic {
public inline function new() this = new SubCookie();
@:arrayAccess function get(key:String):SimpleCookie {
if (!Reflect.hasField(this, key))
Reflect.setField(this, key, new SubCookie());
return Reflect.field(this, key);
}
@:arrayAccess function setString(key:String, value:String):String {
Reflect.setField(this, key, value);
return value;
}

@:arrayAccess function setDynamic(key:String, value:Dynamic):Dynamic {
Reflect.setField(this, key, value);
return value;
}

public inline function keys()
return Reflect.fields(this);
}
212 changes: 49 additions & 163 deletions bin/Cookie.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions bin/Cookie.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 5 additions & 2 deletions bin/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,11 @@
<body>
<script src="Cookie.js"></script>
<script>
var cookies = Cookies.cookies;
Cookies.set("complex","a","1");
//var cookies = Cookies.cookies;
//cookies.a.b = 1;
cookie = Cookies.prototype
console.log(cookie.get("simple"));
console.log(cookie.get("complex","b"));
</script>
</body>
</html>
Loading

0 comments on commit 6bdcefb

Please sign in to comment.