March 04, 2012
On Sunday, 4 March 2012 at 00:05:19 UTC, James Miller wrote:
> Hmm, does your DOM library compile with this?

No. I want do a port of some of the functions to it,
though.

(Even if I fix it to not use goto, so it compiles to JS,
I don't actually need a parser in the browser - it should
use native methods when possible. So, my strategy will
be to port convenience functions instead of the whole thing.)

For Javascript dom stuff, I'm generally happy enough
with the browser's api alone, but my little js file
ports some of my convenience functions:

addChild
insertAfter
prependChild
hasClass
toggleClass
removeClass
addClass
getParent
appendText
replaceText
removeFromTree


All as free functions in Javascript. Together with what
the browser already has, that covers everything I want,
well, except for dataset which is beautiful on the server,
but meh on the client since you have to use getAttribute
for compatibility. But, that's not a big deal.

I didn't port most of my form functions in dom.d because
I just don't do that kind of stuff client side anyway.

(Other stuff in my js lib are some functional programming
helpers and an event compatibility set.)



But, for the D->JS DOM additions, these functions are
pretty much what I want. My strategy I'm considering
is to make a separate document module, that replaces
the browser.document.

Using alias this magic, I'll make extension classes that
are compatible with the real thing, without any runtime
wrapping.

It'll be like a homemade UFCS:

final class BetterElement {
    JSElement __js_this;
    alias __js_this this;

    BetterElement addClass(string c) {
         className ~= " " ~ c;
    }
}

/* do the same for document */

auto be = document.querySelector("#foo > p");
be.addClass("test");

When this is compiled, it comes out as:

function addClass(c, d_this) {
   d_this.className += " " + c;
}

var be = document.querySelector("#foo > p");
addClass("test", be);




Which is about as minimal as you can get in JS (it's
about the same as I wrote by hand), while keeping
the beautiful syntax in D.




Anyway, bottom line is my goal is indeed to have a
compatible version of my dom library for D->JS too, but
it will have almost a completely separate implementation
to be more efficient in the browser environment.
March 04, 2012
On Tuesday, 28 February 2012 at 03:06:12 UTC, Daniel Murphy wrote:
> Cool, please do.

I suck at using git, but I think it works now:

https://github.com/adamdruppe/dmd/tree/dtojs


The backend refused to die in the last 45 minutes,
so I just left it there.


I'm pretty sure it is up to date to real dmd
now too... i hope. Anyway there it is.
March 04, 2012
"Adam D. Ruppe" <destructionator@gmail.com> wrote in message news:uhqgqgsyzzxrctbeftyf@forum.dlang.org...
> On Tuesday, 28 February 2012 at 03:06:12 UTC, Daniel Murphy wrote:
>> Cool, please do.
>
> I suck at using git, but I think it works now:
>
> https://github.com/adamdruppe/dmd/tree/dtojs
>
>
> The backend refused to die in the last 45 minutes,
> so I just left it there.
>
>
> I'm pretty sure it is up to date to real dmd
> now too... i hope. Anyway there it is.

Lol, I think you revered a bunch of stuff when you rebased it.  But so long as future changes are done with git it should be possible to fix the history later.  I'll try and fix this for you sometime this week.  Hopefully this makes some sense.


March 04, 2012
On Sunday, 4 March 2012 at 06:50:48 UTC, Daniel Murphy wrote:
> Lol, I think you revered a bunch of stuff when you rebased it.

git and I don't quite understand each other yet.

$ git eat flaming death
git: 'eat' is not a git command. See 'git --help'.

aaaarrrggggh
March 04, 2012
"Adam D. Ruppe" <destructionator@gmail.com> wrote in message news:gsverzxcnkptoxxsucah@forum.dlang.org...
> On Sunday, 4 March 2012 at 06:50:48 UTC, Daniel Murphy wrote:
>> Lol, I think you revered a bunch of stuff when you rebased it.
>
> git and I don't quite understand each other yet.
>
> $ git eat flaming death
> git: 'eat' is not a git command. See 'git --help'.
>
> aaaarrrggggh

https://www.semitwist.com/articles/article/view/stupid-git

Normally, I just use TortoiseGit. Sooo much nicer. But it's not on Linux.


March 04, 2012
On Saturday, 3 March 2012 at 12:10:47 UTC, Jacob Carlborg wrote:
> On 2012-03-02 15:38, Adam D. Ruppe wrote:
>> On Friday, 2 March 2012 at 05:58:03 UTC, Nick Sabalausky wrote:
>>> You make it sound as if there's another kind of JS.
>>
>> Horribly inefficient relative to the environment :P
>>
>> I just don't want 100 kb of crap to download just to
>> write a hello world.
>>
>> A lot of people prefer to use gzipped sizes, but I don't
>> because the browser still has to parse the whole thing,
>> and that takes time after the download, even if you don't
>> actually run any of it.
>>
>> (On some browsers, it parses it again on every page load!)
>>
>>
>> This generated D code gzips very, very well, but I still
>> want to keep it small in general for general speed.
>>
>> The fastest code is no code at all. Less to parse, less
>> to run.
>
> No, we don't want to do it like Dart:
>
> https://gist.github.com/1277224
>
> 17260 lines of code for Hello World.

To be fair to Dart, that was from the initial preview release of
it.  They managed to get it quite a bit smaller a couple months
ago. https://gist.github.com/1385015

Regards,
Brad Anderson
March 05, 2012
On Sunday, 4 March 2012 at 00:09:11 UTC, Andrej Mitrovic wrote:
> Could export help?

Not for the global (that's handled adequately by dmd's
name mangling anyway), but I did just add export checking
as comments.

export void foo() {}

becomes

function /*export*/ mangled_foo() {}


the idea is then tools like gcfunctions will know
not to strip that function out, since it may be referenced
in another module.

It also occurs to me that .di generation may be useful here
for things like server communication. So that might be
cool.
March 05, 2012
On 2012-03-04 23:29, Brad Anderson wrote:
> On Saturday, 3 March 2012 at 12:10:47 UTC, Jacob Carlborg wrote:
>> On 2012-03-02 15:38, Adam D. Ruppe wrote:
>>> On Friday, 2 March 2012 at 05:58:03 UTC, Nick Sabalausky wrote:
>>>> You make it sound as if there's another kind of JS.
>>>
>>> Horribly inefficient relative to the environment :P
>>>
>>> I just don't want 100 kb of crap to download just to
>>> write a hello world.
>>>
>>> A lot of people prefer to use gzipped sizes, but I don't
>>> because the browser still has to parse the whole thing,
>>> and that takes time after the download, even if you don't
>>> actually run any of it.
>>>
>>> (On some browsers, it parses it again on every page load!)
>>>
>>>
>>> This generated D code gzips very, very well, but I still
>>> want to keep it small in general for general speed.
>>>
>>> The fastest code is no code at all. Less to parse, less
>>> to run.
>>
>> No, we don't want to do it like Dart:
>>
>> https://gist.github.com/1277224
>>
>> 17260 lines of code for Hello World.
>
> To be fair to Dart, that was from the initial preview release of
> it. They managed to get it quite a bit smaller a couple months
> ago. https://gist.github.com/1385015
>
> Regards,
> Brad Anderson

Seems they found a way to not include the complete runtime every time.

-- 
/Jacob Carlborg
March 07, 2012
"Adam D. Ruppe" <destructionator@gmail.com> wrote in message news:mxstsriydkbxxrjlfxqn@forum.dlang.org...
>
> Then again, when giant things like jQuery is considered
> a "necessity" when I get by just fine with my 10 KB
> (source, not minified, not gzipped) custom library,
> if even that, it shows there's a big disconnect between
> me and most other web people nowadays.

Yea, a disconnect of about 50 IQ points (in your favor).

Things like that are why I hate "typical" web developers and webdev "conventional wisdom" (hah!) with a burning passion. We're talking "thermonuclear power of a thousand suns" here.


March 07, 2012
On 7 March 2012 16:19, Nick Sabalausky <a@a.a> wrote:
> "Adam D. Ruppe" <destructionator@gmail.com> wrote in message news:mxstsriydkbxxrjlfxqn@forum.dlang.org...
>>
>> Then again, when giant things like jQuery is considered
>> a "necessity" when I get by just fine with my 10 KB
>> (source, not minified, not gzipped) custom library,
>> if even that, it shows there's a big disconnect between
>> me and most other web people nowadays.
>
> Yea, a disconnect of about 50 IQ points (in your favor).
>
> Things like that are why I hate "typical" web developers and webdev "conventional wisdom" (hah!) with a burning passion. We're talking "thermonuclear power of a thousand suns" here.
>
>

I don't know what webdev "conventional wisdom" is, but it would be nice to use site that don't eat my CPU because of a billion different javascript, erm, scripts all trying to do things. There's something to be said for rolling your own libraries.

However, I would like jQuery's CSS selector engine as a standalone library, sooo much easier than complex DOM lookups, especially when you want something fairly specific.

--
James Miller