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

[ENH] Javascript Condition with else decoration (JSConditionElse) #830

Closed
GoogleCodeExporter opened this issue Mar 25, 2015 · 2 comments
Closed

Comments

@GoogleCodeExporter
Copy link

I was trying to implement a classical "if {...} else {...}" object using 
JSDecorations.
Then I found there is a JSCondition, but there is no way to describe an "else" 
statement.

Also there is an JSIfThenElse decoration, but it is implemented as a ternary 
operator (x ? y : z) instead of 'if(x){ y} else {z}'

So I added an extension to JSObject, named #condition:else: and also a 
JSConditionElse decoration which produces the expected output.

Can this be added to the main trunk of the Javascript-Core package?

The changes are attached.


With these modifications I was able to transform this Javascript:
    $('#ajaxId tbody').on( 'click', 'tr', function () {
        if ( $(this).hasClass('selected') ) {
            $(this).removeClass('selected');
        }
        else {
            $('#ajaxId tr.selected').removeClass('selected');
            $(this).addClass('selected');
        }
    } );

Into this:

    | selClass |
    selClass := 'selected'.
    ^ (html jQuery: '#' , self ajaxId , ' tbody')
        on: 'click'
        selector: 'tr'
        do:
            ((html jQuery this removeClass: selClass)
                condition: (html jQuery this hasClass: selClass)
                else:
                    (JSScript new
                        add: ((html jQuery: '#' , self ajaxId , ' tr.' , selClass) removeClass: selClass);
                        add: (html jQuery this addClass: selClass);
                        yourself))

Original issue reported on code.google.com by emaring...@gmail.com on 30 Sep 2014 at 3:06

Attachments:

@GoogleCodeExporter
Copy link
Author

Original comment by jo...@yesplan.be on 2 Oct 2014 at 6:59

  • Changed state: Accepted
  • Added labels: ****
  • Removed labels: ****

@GoogleCodeExporter
Copy link
Author

Name: Javascript-Core-JohanBrichau.98
Author: JohanBrichau
Time: 2 October 2014, 9:21:16.807292 pm
UUID: 3b250d7f-bd9b-4d4a-9ba9-f077a1f57fe2
Ancestors: Javascript-Core-pmm.97

Issue 830:  [ENH] Javascript Condition with else decoration (JSConditionElse)

Original comment by jo...@yesplan.be on 2 Oct 2014 at 7:21

  • Changed state: Fixed
  • Added labels: ****
  • Removed labels: ****

@marschall marschall added this to the 3.2 milestone Jul 15, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants