haxetink / tink_anon Goto Github PK
View Code? Open in Web Editor NEWAnonymous object voodoo.
License: The Unlicense
Anonymous object voodoo.
License: The Unlicense
var o:{a:Foo, b:Foo};
splat(o, _.foo); // or splat(o, 'foo'); or any similar syntax
// becomes:
var a = o.a.foo;
var b = o.b.foo;
@nadako dropped this gist in the haxe gitter some time ago: https://gist.github.com/nadako/7edbc859e5206b2dbd65df2fd96aa334
Seems like it could be a good fit to add something like this to tink_anon?
db.Foo.select({ foo: Foo.foo }).next( o -> tink.Anon.merge( o, ref = transform(o.ref)));
fails compilation with:
expected type should be struct or @:structInit
.
These variants work though:
.next( o -> { var r = tink.Anon.merge( o, ref = transform(o.ref)) ); r; }
.next( o -> Success(tink.Anon.merge( o, ref = transform(o.ref))) )
.next( o -> o = tink.Anon.merge( o, ref = transform(o.ref)) )
I'm going to use the last one for the time being.
using tink.Anon;
using tink.CoreApi;
typedef DataServerListObj = {
@:optional var from:Int;
@:optional var to:Int;
}
typedef SType = {
@:optional var infor:String;
}
class Main {
function new() {}
static public function main() {
var obj:DataServerListObj = {from: 1};
var st:SType = {infor: "d"};
trace(obj);// { from: 1 } instead of { from: 1 ,to:undefind};
var m = obj.merge(st);
trace(m); // I don't expected to=undefined here that I not set
}
}
This does not work:
var a = {v: "none"};
function getResult(isYes:Bool)
return tink.Anon.merge(a, isYes ? {v:"it works"} : {});
trace(getResult(true));
trace(getResult(false));
OTOH this works:
tink.Anon.merge(a, {v: isYes ? "it works" : ""});
I believe it is not trivial thing to fix (if even possible) so adding a compilation error and a notion to readme about this kinds of limitation would be useful.
var o = EitherType<{i:1}, Array<{i:1}>> = merge(i = 1);
Could the macro be clever enough to figure out what to produce? If it can rule out impossible outputs (Array in this case) then it should be easy. Otherwise if the two types are both structures it might have to "try"...
Ensuring the same runtime structure for anonymous objects of the same compile time structure generally makes life easier for JITs.
It also has a couple of adverse effects though, so it should be customizable.
See title. Consider supporting @:privateAccess
as well.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.