Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Keep reference to this #3

Closed
wants to merge 1 commit into from
Closed

Keep reference to this #3

wants to merge 1 commit into from

Conversation

Artazor
Copy link
Contributor

@Artazor Artazor commented Aug 13, 2014

Hi. I'm working on semi-conservative refactoring of mixins in jade (all existing unit tests are passed, only private api slightly changed) to make them first class objects, as well as proper handling of this refernece in templates. In classical jade this reference is used for passing of {block,attributes} to the mixin like

    var buf, jade // runtime vars enclosed into template's closure 
    mixin.call({block,attributes}, args...)

I've refactored lexer/parser/compiler + with
to make mixins essentialy a curried functions while decoupling them from jade-runtime and buf:

      mixin(args...)(attributes,block)(buf, jade)

so now mixins can be compiled separately with jade.compileMethod(src, options) and passed as parameters for templates, or attached to function prototype to make templates as methods, or simply bound by mixin.bind(someobj)

also i've added first-class mixin call syntax

       +[expression_that_evaluates_to_mixin]#id.class(data-test=123)(arg1,agr2,arg3)
             span I'm in block
       +[jade_mixins["test"]](1,2,3)
       +test(1,2,3)
       +[obj.renderView] //- this was a primary goal

All this features are based on small enhancement of with module to make it respectful for this reference.
My semantics/syntax for mixins is arguable but I hope that at least this change in with matters and can be merged.

Regards, Anatoly
P.S. my fork of jade is here https://github.com/Artazor/jade - it would be great to hear any comments about that direction

@@ -46,7 +46,7 @@ function addWith(obj, src, exclude) {

src = '(function (' + vars.join(', ') + ') {' +
src +
'}(' + inputVars.join(',') + '))'
'}.bind(this)(' + inputVars.join(',') + '))'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we fix this to use .call(this, ...args) rather than .bind(this)(...args)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Stop!!! Then you should change AST checking too! otherwise it will fail.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh I see, you've changed AST checking too -)
Sorry, I'm thinking at lower speed than you probably

@ForbesLindesay
Copy link
Member

FYI, I like the idea of making mixins first class values that can be passed around until they are used. I'm not entirely clear on the relevance of this here and the syntax may need a little more bike-shedding before it is merged. I'd like to have that discussion in the jade repo though, where the relevant people can watch, so please open an issue there so that this can be discussed, or add your thoughts to existing issues.

@ForbesLindesay
Copy link
Member

As for this pull request, there is no question about it, this should be supported by with.

@Artazor
Copy link
Contributor Author

Artazor commented Aug 19, 2014

Hi! Thank you for the reply! I'm working on the text for the detailed
explanation and it will be in jade's issues soon (as proposal)
On Aug 19, 2014 7:59 PM, "Forbes Lindesay" [email protected] wrote:

FYI, I like the idea of making mixins first class values that can be
passed around until they are used. I'm not entirely clear on the relevance
of this here and the syntax may need a little more bike-shedding before
it is merged. I'd like to have that discussion in the jade repo though,
where the relevant people can watch, so please open an issue there so that
this can be discussed, or add your thoughts to existing issues.


Reply to this email directly or view it on GitHub
#3 (comment).

@ForbesLindesay
Copy link
Member

I've merged this manually, with a small modification. Thanks for the contribution!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants