<commit_before>define(['helpers/CodeChooser'], function(CodeChooser){
    describe('CodeChooser', function (){

        var testdata = {
            firstprop: "firstvalue",
            secondprop: "secondvalue",
            thirdprop: "thirdvalue"};

        var emptyObject = {};

        beforeEach(function(){
        });

        it("should be able to return the first property (object has one or more properties)", function (){
            var chooser = new CodeChooser(testdata);
            var firstProp = chooser.getFirstProperty(testdata);

            var expectedResult = "firstvalue";

            expect(firstProp).toEqual(expectedResult);
        });

        it("should be able to handle empty objects", function (){
            var chooser = new CodeChooser(testdata);
            var firstProp = chooser.getFirstProperty(emptyObject);

            var expectedResult = undefined;

            expect(firstProp).toEqual(expectedResult);
        });

        /*it("should be able to fetch an ICD dataset", function(){
            var chooser = new CodeChooser();
            chooser.fetchDatasets("icd", "A045", function(data) {
                var expectedJSON = "adföafg";

                expect(dataContainer).toEqual(expectedJSON);
            });
        });*/

        it("should support async execution of test preparation and expectations", function() {
            var expectedJSON = "blah";
            var actualJSON;
            var flag = false;

            runs(function() {
                flag = false;
                var chooser = new CodeChooser();
                chooser.fetchDatasets("icd", "A045", function(data) {
                    actualJSON = data;
                });

                setTimeout(function() {
                    flag = true;
                }, 2000);
            });

            waitsFor(function() {
                return flag;
            }, "The Value should be incremented", 2100);

            runs(function() {
                expect(actualJSON).toEqual(expectedJSON);
            });
        });
    });
});<commit_msg>First API call test succeeds :)<commit_after>define(['helpers/CodeChooser'], function(CodeChooser){
    describe('CodeChooser', function (){

        var testdata = {
            firstprop: "firstvalue",
            secondprop: "secondvalue",
            thirdprop: "thirdvalue"};

        var ICD_A045 = [ { code : 'A045', description : 'Enteritis durch Campylobacter', year : 2013, icd_code_id : { $oid : '5490074848e276ea1b793f79' }, categorised_data : { categories : { interval : [ { categories : { percentile : [ { categories : {  }, percentile : 5, amount : 3 }, { categories : {  }, percentile : 10, amount : 4 }, { categories : {  }, percentile : 25, amount : 5 }, { categories : {  }, percentile : 50, amount : 7 }, { categories : {  }, percentile : 75, amount : 9 }, { categories : {  }, percentile : 90, amount : 14 }, { categories : {  }, percentile : 95, amount : 18 } ] }, interval : { from : 70 }, n : 377, dad : 8, sa : 4, min : 2, max : 30 } ] } } }, { code : 'A045', description : 'Enteritis durch Campylobacter', year : 2013, icd_code_id : { $oid : '5490074848e276ea1b793f79' }, categorised_data : { categories : { interval : [ { categories : { percentile : [ { categories : {  }, percentile : 5, amount : 3 }, { categories : {  }, percentile : 10, amount : 3 }, { categories : {  }, percentile : 25, amount : 4 }, { categories : {  }, percentile : 50, amount : 5 }, { categories : {  }, percentile : 75, amount : 6 }, { categories : {  }, percentile : 90, amount : 8 }, { categories : {  }, percentile : 95, amount : 9 } ] }, interval : { from : 40, to : 69 }, n : 415, dad : 5, sa : 2, min : 1, max : 19 } ] } } }, { code : 'A045', description : 'Enteritis durch Campylobacter', year : 2013, icd_code_id : { $oid : '5490074848e276ea1b793f79' }, categorised_data : { categories : { interval : [ { categories : { percentile : [ { categories : {  }, percentile : 5, amount : 2 }, { categories : {  }, percentile : 10, amount : 2 }, { categories : {  }, percentile : 25, amount : 2 }, { categories : {  }, percentile : 50, amount : 3 }, { categories : {  }, percentile : 75, amount : 4 }, { categories : {  }, percentile : 90, amount : 5 }, { categories : {  }, percentile : 95, amount : 5 } ] }, interval : { from : 0, to : 14 }, n : 63, dad : 3, sa : 1, min : 2, max : 11 } ] } } }, { code : 'A045', description : 'Enteritis durch Campylobacter', year : 2013, icd_code_id : { $oid : '5490074848e276ea1b793f79' }, categorised_data : { categories : { interval : [ { categories : { percentile : [ { categories : {  }, percentile : 5, amount : 2 }, { categories : {  }, percentile : 10, amount : 2 }, { categories : {  }, percentile : 25, amount : 3 }, { categories : {  }, percentile : 50, amount : 4 }, { categories : {  }, percentile : 75, amount : 5 }, { categories : {  }, percentile : 90, amount : 6 }, { categories : {  }, percentile : 95, amount : 7 } ] }, interval : { from : 15, to : 39 }, n : 322, dad : 3, sa : 1, min : 2, max : 11 } ] } } } ];

        var emptyObject = {};

        beforeEach(function(){
        });

        it("should be able to return the first property (object has one or more properties)", function (){
            var chooser = new CodeChooser(testdata);
            var firstProp = chooser.getFirstProperty(testdata);

            var expectedResult = "firstvalue";

            expect(firstProp).toEqual(expectedResult);
        });

        it("should be able to handle empty objects", function (){
            var chooser = new CodeChooser(testdata);
            var firstProp = chooser.getFirstProperty(emptyObject);

            var expectedResult = undefined;

            expect(firstProp).toEqual(expectedResult);
        });

        //tests the api call
        it("should support async execution of test preparation and expectations", function() {
            var expectedJSON = ICD_A045;
            var actualJSON;
            var flag = false;

            runs(function() {
                flag = false;
                var chooser = new CodeChooser();
                chooser.fetchDatasets("icd", "A045", function(data) {
                    actualJSON = data;
                });

                setTimeout(function() {
                    flag = true;
                }, 50);
            });

            waitsFor(function() {
                return flag;
            }, "The Value should be incremented", 200);

            runs(function() {
                expect(actualJSON).toEqual(expectedJSON);
            });
        });
    });
});<|endoftext|>


<commit_before>/**
 *
 */
App.Product = DS.Model.extend(
{
  title: DS.attr('string'),
  description: DS.attr('string'),
  page: DS.attr('string'),
  content: DS.attr('string'),
  last_price: DS.attr('number'),
  currency: DS.attr('string'),
  bonus_money: DS.attr('number'),
  bonus_percent: DS.attr('number'),
  bonus_text: DS.attr('string'),
  /**
   *
   */
  price: function()
  {
    return parseFloat(this.get('last_price'), 10).toFixed(2) + ' ' + this.get('currency');
  }.property('last_price', 'currency'),
  /**
   *
   */
  cashback: function()
  {
    var bonusMoney = this.get('bonus_money');
    var bonusPercent = this.get('bonus_percent');
    var bonusText = this.get('bonus_text');

    var ret = 'Cashback: ';
    if (bonusMoney)
    {
      ret += bonusMoney + ' ' + this.get('currency')
      if (bonusPercent)
      {
        ret += ' & ';
      }
    }
    if (bonusPercent)
    {
      ret += bonusPercent + ' %';
    }

    return ret;
  }.property('bonus_money', 'bonus_percent', 'bonus_text')
});
<commit_msg>make the product's categories accessible<commit_after>/**
 *
 */
App.Product = DS.Model.extend(
{
  title: DS.attr('string'),
  description: DS.attr('string'),
  page: DS.attr('string'),
  content: DS.attr('string'),
  last_price: DS.attr('number'),
  currency: DS.attr('string'),
  bonus_money: DS.attr('number'),
  bonus_percent: DS.attr('number'),
  bonus_text: DS.attr('string'),
  categories: DS.attr('raw'),
  /**
   *
   */
  price: function()
  {
    return parseFloat(this.get('last_price'), 10).toFixed(2) + ' ' + this.get('currency');
  }.property('last_price', 'currency'),
  /**
   *
   */
  cashback: function()
  {
    var bonusMoney = this.get('bonus_money');
    var bonusPercent = this.get('bonus_percent');
    var bonusText = this.get('bonus_text');

    var ret = 'Cashback: ';
    if (bonusMoney)
    {
      ret += bonusMoney + ' ' + this.get('currency')
      if (bonusPercent)
      {
        ret += ' & ';
      }
    }
    if (bonusPercent)
    {
      ret += bonusPercent + ' %';
    }

    return ret;
  }.property('bonus_money', 'bonus_percent', 'bonus_text')
});
<|endoftext|>


<commit_before>describe('LinkManager', function () {
  'use strict';

  var sandbox;

  beforeEach(function(done) {
    var self = this;

    requirejs([
      'phantom-shims',
      'jquery',
      'LinkManager',
      'eventsWithPromises'
    ],
    function (
      phantomShims,
      $,
      LinkManager,
      eventsWithPromises
    ) {
      self.$html = $(window.__html__['spec/javascripts/fixtures/LinkManager.html']).appendTo('body');
      self.$fixture = self.$html.find('[data-dough-component="LinkManager"]');
      self.LinkManager = LinkManager;
      self.eventsWithPromises = eventsWithPromises;
      sandbox = sinon.sandbox.create();
      done();
    }, done);
  });

  afterEach(function() {
    this.$html.remove();
    sandbox.restore();
    this.eventsWithPromises.unsubscribeAll();
  });

  describe('Initialisation', function () {
    beforeEach(function (done) {
      this.component = new this.LinkManager(this.$fixture);
      done();
    });

    it('should cache the insert link, tab trigger, value triggers and tab trigger element references', function() {
      this.component.init();
      expect(this.component.$tabTriggers.length).to.be.at.least(1);
      expect(this.component.$insertLinks.length).to.be.at.least(1);
      expect(this.component.$valueTriggers.length).to.be.at.least(1);
    });
  });

  describe('App Events', function () {
    beforeEach(function (done) {
      this.component = new this.LinkManager(this.$fixture);
      done();
    });

    it('should call handleShown when the cmseditor:link-published event is published', function() {
      var spy = sandbox.spy(this.LinkManager.prototype, '_handleShown');

      this.component.init();
      this.eventsWithPromises.publish('cmseditor:link-published', {
        emitter: 'add-link'
      });
      expect(spy.called).to.be.true;
    });

    it('should call the close method when the dialog:close or dialog:cancelled event with matching emitter context is published', function() {
      var spy = sandbox.spy(this.LinkManager.prototype, 'close'),
          eventData = {
            emitter: 'add-link'
          };

      this.component.init();

      this.eventsWithPromises.publish('dialog:closed', eventData);
      this.eventsWithPromises.publish('dialog:cancelled', eventData);

      expect(spy.callCount).to.equal(2);
    });
  });

  describe('When dialog is opened', function () {
    beforeEach(function (done) {
      this.component = new this.LinkManager(this.$fixture);
      done();
    });

    it('cmseditor:link-published event\'s emitter ID should be the same as the LinkManager\'s', function() {
      var spy = sandbox.spy(this.LinkManager.prototype, '_handleShown');

      this.component.init();
      this.eventsWithPromises.publish('cmseditor:link-published', {
        emitter: 'add-link'
      });
      expect(spy.args[0][0].emitter).to.equal('add-link');
    });

    describe('Editing existing link', function () {
      it('should call the setup function with "existing" param and link', function() {
        var spy = sandbox.spy(this.LinkManager.prototype, '_setup');

        this.component.init();
        this.eventsWithPromises.publish('cmseditor:link-published', {
          emitter: 'add-link',
          link: 'foo'
        });

        expect(spy.calledWith('existing', 'foo')).to.be.true;
      });
    });

    describe('Creating a new link', function () {
      it('should call the setup function with "new" param', function() {
        var spy = sandbox.spy(this.LinkManager.prototype, '_setup');

        this.component.init();
        this.eventsWithPromises.publish('cmseditor:link-published', {
          emitter: 'add-link'
        });

        expect(spy.calledWith('new')).to.be.true;
      });
    });
  });

  describe('UI Events', function () {
    beforeEach(function (done) {
      this.component = new this.LinkManager(this.$fixture);
      done();
    });

    describe('When link is edited', function() {
      it('should activate a tab trigger', function() {
        var spy = sandbox.spy();
        this.component.init();

        $('[data-dough-tab-selector-trigger]').on('click', spy);
        this.component.changeTab('external');
        expect(spy.called).to.be.true;
      });
    });

    describe('When a new link is called', function () {
      it('should activate the "internal" tab trigger', function() {
        var spy = sandbox.spy();
        this.component.init();

        $('[data-dough-tab-selector-trigger="internal"]').on('click', spy);
        this.component.changeTab('internal');
        expect(spy.called).to.be.true;
      });
    });

    describe('When a link is being edited', function () {
      it('should call the update link function when a text input trigger element\'s value is updated', function () {
        var spy = sandbox.spy(this.LinkManager.prototype, 'setLink'),
            fakeEvent = $.Event('keyup'),
            $textInput,
            textInputType,
            textInputVal;

        this.component.init();

        $textInput = this.component.$valueTriggers.filter(':text').first();
        textInputType = $textInput.attr('data-dough-linkmanager-link-type');
        textInputVal = $textInput.val();

        $textInput.attr('data-dough-linkmanager-link-type', 'external');
        $textInput.val('bar').trigger(fakeEvent);

        expect(spy.calledWith('external','bar')).to.be.true;

        $textInput.attr('data-dough-linkmanager-link-type', textInputType).val(textInputVal);
      });

      it('should call the update link function when a radio trigger element\'s option is selected', function () {
        var spy = sandbox.spy(this.LinkManager.prototype, 'setLink'),
            $radioInput,
            radioInputType,
            radioInputVal;

        this.component.init();

        $radioInput = this.component.$valueTriggers.filter(':radio').first();
        radioInputType = $radioInput.attr('data-dough-linkmanager-link-type');
        radioInputVal = $radioInput.val();

        $radioInput.attr('data-dough-linkmanager-link-type', 'external');
        $radioInput
          .val('bar')
          .click();

        expect(spy.calledWith('external','bar')).to.be.true;

        $radioInput.attr('data-dough-linkmanager-link-type', radioInputType).val(radioInputVal);
      });
    });

    describe('When an Insert Link button is clicked', function () {
      it('should call the _handleInsertLink method', function() {
        var spy = sandbox.spy(this.LinkManager.prototype, '_handleInsertLink');
        this.component.init();
        this.component.$insertLinks.first().click();
        expect(spy.called).to.be.true;
      });
    });
  });

  describe('Insert Link handler', function () {
    beforeEach(function (done) {
      this.component = new this.LinkManager(this.$fixture);
      done();
    });

    it('should call the changeTab method', function() {
      var spy = sandbox.spy(this.LinkManager.prototype, 'changeTab');
      this.component.init();
      this.component.$insertLinks.first().click();
      expect(spy.calledWith('internal')).to.be.true;
    });

    it('should call the publishLink method', function() {
      var spy = sandbox.spy(this.LinkManager.prototype, 'publishLink'),
          $insertLink;

      this.component.init();
      this.component.setLink('internal', 'foo');
      this.component.$insertLinks.first().click();

      expect(spy.calledWith('foo')).to.be.true;

    });

    it('should call the clearInputs method', function() {
      var spy = sandbox.spy(this.LinkManager.prototype, 'clearInputs');
      this.component.init();
      this.component.$insertLinks.first().click();
      expect(spy.called).to.be.true;
    });

      // it('should execute the publish the link when an insertlink button is selected', function() {
      //   var spy = sandbox.spy(this.LinkManager.prototype, '_handleLink');

      //   this.component.$valueTriggers
      //     .filter(':radio')
      //     .first()
      //     .val('foo')
      //     .click();

      //   this.eventsWithPromises.subscribe('linkmanager:link-published', spy);
      //   this.component.$insertLinks.first().click();
      //   expect(spy.called).to.be.true;
      // });
  });

  describe('Checks link type (link to internal page, external page or a file)', function () {
    beforeEach(function (done) {
      this.component = new this.LinkManager(this.$fixture);
      this.component.init();
      done();
    });

    it('should return an internal link type' , function() {
      expect(this.component._getLinkType('/en/articles/foo')).to.equal('internal');
    });

    it('should return an external link type', function() {
      expect(this.component._getLinkType('http://www.foo.com')).to.equal('external');
    });

    it('should return an external file type', function() {
      expect(this.component._getLinkType('http://www.foo.com/file.pdf')).to.equal('external');
    });

    it('should return an internal file type' , function() {
      expect(this.component._getLinkType('/file.pdf')).to.equal('internal');
    });

    it('should return false if no link type is found' , function() {
      expect(this.component._getLinkType('foo')).to.be.false;
    });
  });

  describe('Updating the link value inputs', function () {
    beforeEach(function (done) {
      this.component = new this.LinkManager(this.$fixture);
      this.component.init();
      done();
    });

    afterEach(function () {
      this.component.$linkInputs.filter('[data-dough-linkmanager-link-type="internal"]').val('/foo');
      this.component.$linkInputs.filter('[data-dough-linkmanager-link-type="external"]').val('http://foo.com');
      this.component.$linkInputs.filter('[data-dough-linkmanager-link-type="file"]').val('foo.pdf');
    });

    it('should set the internal link value inputs with the passed link', function () {
      this.component.setInputs('internal', '/bar');
      expect(this.component.$linkInputs.filter('[data-dough-linkmanager-link-type="internal"]').first().val()).to.equal('/bar');
    });

    it('should set the external link value inputs with the passed link', function () {
      this.component.setInputs('external', 'http://bar.com');
      expect(this.component.$linkInputs.filter('[data-dough-linkmanager-link-type="external"]').first().val()).to.equal('http://bar.com');
    });

    it('should set the file link value inputs with the passed link', function () {
      this.component.setInputs('file', 'bar.pdf');
      expect(this.component.$linkInputs.filter('[data-dough-linkmanager-link-type="file"]').first().val()).to.equal('bar.pdf');
    });
  });

  describe('Publish link', function () {
    beforeEach(function (done) {
      this.component = new this.LinkManager(this.$fixture);
      this.component.init();
      done();
    });

    it('should publish the link variable and emitter ID via the events bus', function() {
      var spy = sandbox.spy(),
          link = 'http://www.foo.com';

      this.eventsWithPromises.subscribe('linkmanager:link-published', spy);

      this.component.setLink('internal', link);
      this.component.publishLink(link);

      expect(spy.args[0][0].link).to.equal(link);
      expect(spy.args[0][0].emitter).to.equal('add-link');
    });
  });

  describe('Track the currently selected link', function () {
    beforeEach(function (done) {
      this.component = new this.LinkManager(this.$fixture);
      this.component.init();
      done();
    });

    it('should set the link variable', function() {
      var link = 'http://foo.com';

      this.component.setLink('internal', link);
      expect(this.component.linkValues['internal']).to.eq(link);
    });
  });

  describe('Get a link from the linkValues hash', function () {
    beforeEach(function (done) {
      this.component = new this.LinkManager(this.$fixture);
      this.component.init();
      done();
    });
    it('should return the correct link based type', function() {
      var link = 'http://foo.com';

      this.component.setLink('internal', link);
      expect(this.component.getLink('internal')).to.equal(link);
    });
  });

  describe('Close', function () {
    beforeEach(function (done) {
      this.component = new this.LinkManager(this.$fixture);
      this.component.init();
      done();
    });

    it('should call the changeTab and clearInputs to reset the view', function() {
      var changeTabSpy = sandbox.spy(this.LinkManager.prototype, 'changeTab'),
          clearInputsSpy = sandbox.spy(this.LinkManager.prototype, 'clearInputs');

      this.component.close();

      expect(changeTabSpy.calledWith('internal')).to.be.true;
      expect(clearInputsSpy.called).to.be.true;
    });
  });

});
<commit_msg>Improve suite naming<commit_after>describe('LinkManager', function () {
  'use strict';

  var sandbox;

  beforeEach(function(done) {
    var self = this;

    requirejs([
      'phantom-shims',
      'jquery',
      'LinkManager',
      'eventsWithPromises'
    ],
    function (
      phantomShims,
      $,
      LinkManager,
      eventsWithPromises
    ) {
      self.$html = $(window.__html__['spec/javascripts/fixtures/LinkManager.html']).appendTo('body');
      self.$fixture = self.$html.find('[data-dough-component="LinkManager"]');
      self.LinkManager = LinkManager;
      self.eventsWithPromises = eventsWithPromises;
      sandbox = sinon.sandbox.create();
      done();
    }, done);
  });

  afterEach(function() {
    this.$html.remove();
    sandbox.restore();
    this.eventsWithPromises.unsubscribeAll();
  });

  describe('Initialisation', function () {
    beforeEach(function (done) {
      this.component = new this.LinkManager(this.$fixture);
      done();
    });

    it('should cache the insert link, tab trigger, value triggers and tab trigger element references', function() {
      this.component.init();
      expect(this.component.$tabTriggers.length).to.be.at.least(1);
      expect(this.component.$insertLinks.length).to.be.at.least(1);
      expect(this.component.$valueTriggers.length).to.be.at.least(1);
    });
  });

  describe('App Events', function () {
    beforeEach(function (done) {
      this.component = new this.LinkManager(this.$fixture);
      done();
    });

    it('should call handleShown when the cmseditor:link-published event is published', function() {
      var spy = sandbox.spy(this.LinkManager.prototype, '_handleShown');

      this.component.init();
      this.eventsWithPromises.publish('cmseditor:link-published', {
        emitter: 'add-link'
      });
      expect(spy.called).to.be.true;
    });

    it('should call the close method when the dialog:close or dialog:cancelled event with matching emitter context is published', function() {
      var spy = sandbox.spy(this.LinkManager.prototype, 'close'),
          eventData = {
            emitter: 'add-link'
          };

      this.component.init();

      this.eventsWithPromises.publish('dialog:closed', eventData);
      this.eventsWithPromises.publish('dialog:cancelled', eventData);

      expect(spy.callCount).to.equal(2);
    });
  });

  describe('When dialog is opened', function () {
    beforeEach(function (done) {
      this.component = new this.LinkManager(this.$fixture);
      done();
    });

    it('cmseditor:link-published event\'s emitter ID should be the same as the LinkManager\'s', function() {
      var spy = sandbox.spy(this.LinkManager.prototype, '_handleShown');

      this.component.init();
      this.eventsWithPromises.publish('cmseditor:link-published', {
        emitter: 'add-link'
      });
      expect(spy.args[0][0].emitter).to.equal('add-link');
    });

    describe('Editing existing link', function () {
      it('should call the setup function with "existing" param and link', function() {
        var spy = sandbox.spy(this.LinkManager.prototype, '_setup');

        this.component.init();
        this.eventsWithPromises.publish('cmseditor:link-published', {
          emitter: 'add-link',
          link: 'foo'
        });

        expect(spy.calledWith('existing', 'foo')).to.be.true;
      });
    });

    describe('Creating a new link', function () {
      it('should call the setup function with "new" param', function() {
        var spy = sandbox.spy(this.LinkManager.prototype, '_setup');

        this.component.init();
        this.eventsWithPromises.publish('cmseditor:link-published', {
          emitter: 'add-link'
        });

        expect(spy.calledWith('new')).to.be.true;
      });
    });
  });

  describe('UI Events', function () {
    beforeEach(function (done) {
      this.component = new this.LinkManager(this.$fixture);
      done();
    });

    describe('When link is edited', function() {
      it('should activate a tab trigger', function() {
        var spy = sandbox.spy();
        this.component.init();

        $('[data-dough-tab-selector-trigger]').on('click', spy);
        this.component.changeTab('external');
        expect(spy.called).to.be.true;
      });
    });

    describe('When a new link is called', function () {
      it('should activate the "internal" tab trigger', function() {
        var spy = sandbox.spy();
        this.component.init();

        $('[data-dough-tab-selector-trigger="internal"]').on('click', spy);
        this.component.changeTab('internal');
        expect(spy.called).to.be.true;
      });
    });

    describe('When a link is being edited', function () {
      it('should call the update link function when a text input trigger element\'s value is updated', function () {
        var spy = sandbox.spy(this.LinkManager.prototype, 'setLink'),
            fakeEvent = $.Event('keyup'),
            $textInput,
            textInputType,
            textInputVal;

        this.component.init();

        $textInput = this.component.$valueTriggers.filter(':text').first();
        textInputType = $textInput.attr('data-dough-linkmanager-link-type');
        textInputVal = $textInput.val();

        $textInput.attr('data-dough-linkmanager-link-type', 'external');
        $textInput.val('bar').trigger(fakeEvent);

        expect(spy.calledWith('external','bar')).to.be.true;

        $textInput.attr('data-dough-linkmanager-link-type', textInputType).val(textInputVal);
      });

      it('should call the update link function when a radio trigger element\'s option is selected', function () {
        var spy = sandbox.spy(this.LinkManager.prototype, 'setLink'),
            $radioInput,
            radioInputType,
            radioInputVal;

        this.component.init();

        $radioInput = this.component.$valueTriggers.filter(':radio').first();
        radioInputType = $radioInput.attr('data-dough-linkmanager-link-type');
        radioInputVal = $radioInput.val();

        $radioInput.attr('data-dough-linkmanager-link-type', 'external');
        $radioInput
          .val('bar')
          .click();

        expect(spy.calledWith('external','bar')).to.be.true;

        $radioInput.attr('data-dough-linkmanager-link-type', radioInputType).val(radioInputVal);
      });
    });

    describe('When an Insert Link button is clicked', function () {
      it('should call the _handleInsertLink method', function() {
        var spy = sandbox.spy(this.LinkManager.prototype, '_handleInsertLink');
        this.component.init();
        this.component.$insertLinks.first().click();
        expect(spy.called).to.be.true;
      });
    });
  });

  describe('Insert Link handler', function () {
    beforeEach(function (done) {
      this.component = new this.LinkManager(this.$fixture);
      done();
    });

    it('should call the changeTab method', function() {
      var spy = sandbox.spy(this.LinkManager.prototype, 'changeTab');
      this.component.init();
      this.component.$insertLinks.first().click();
      expect(spy.calledWith('internal')).to.be.true;
    });

    it('should call the publishLink method', function() {
      var spy = sandbox.spy(this.LinkManager.prototype, 'publishLink'),
          $insertLink;

      this.component.init();
      this.component.setLink('internal', 'foo');
      this.component.$insertLinks.first().click();

      expect(spy.calledWith('foo')).to.be.true;

    });

    it('should call the clearInputs method', function() {
      var spy = sandbox.spy(this.LinkManager.prototype, 'clearInputs');
      this.component.init();
      this.component.$insertLinks.first().click();
      expect(spy.called).to.be.true;
    });

      // it('should execute the publish the link when an insertlink button is selected', function() {
      //   var spy = sandbox.spy(this.LinkManager.prototype, '_handleLink');

      //   this.component.$valueTriggers
      //     .filter(':radio')
      //     .first()
      //     .val('foo')
      //     .click();

      //   this.eventsWithPromises.subscribe('linkmanager:link-published', spy);
      //   this.component.$insertLinks.first().click();
      //   expect(spy.called).to.be.true;
      // });
  });

  describe('Checks link type (link to internal page, external page or a file)', function () {
    beforeEach(function (done) {
      this.component = new this.LinkManager(this.$fixture);
      this.component.init();
      done();
    });

    it('should return an internal link type' , function() {
      expect(this.component._getLinkType('/en/articles/foo')).to.equal('internal');
    });

    it('should return an external link type', function() {
      expect(this.component._getLinkType('http://www.foo.com')).to.equal('external');
    });

    it('should return an external file type', function() {
      expect(this.component._getLinkType('http://www.foo.com/file.pdf')).to.equal('external');
    });

    it('should return an internal file type' , function() {
      expect(this.component._getLinkType('/file.pdf')).to.equal('internal');
    });

    it('should return false if no link type is found' , function() {
      expect(this.component._getLinkType('foo')).to.be.false;
    });
  });

  describe('Updating the link value inputs', function () {
    beforeEach(function (done) {
      this.component = new this.LinkManager(this.$fixture);
      this.component.init();
      done();
    });

    afterEach(function () {
      this.component.$linkInputs.filter('[data-dough-linkmanager-link-type="internal"]').val('/foo');
      this.component.$linkInputs.filter('[data-dough-linkmanager-link-type="external"]').val('http://foo.com');
      this.component.$linkInputs.filter('[data-dough-linkmanager-link-type="file"]').val('foo.pdf');
    });

    it('should set the internal link value inputs with the passed link', function () {
      this.component.setInputs('internal', '/bar');
      expect(this.component.$linkInputs.filter('[data-dough-linkmanager-link-type="internal"]').first().val()).to.equal('/bar');
    });

    it('should set the external link value inputs with the passed link', function () {
      this.component.setInputs('external', 'http://bar.com');
      expect(this.component.$linkInputs.filter('[data-dough-linkmanager-link-type="external"]').first().val()).to.equal('http://bar.com');
    });

    it('should set the file link value inputs with the passed link', function () {
      this.component.setInputs('file', 'bar.pdf');
      expect(this.component.$linkInputs.filter('[data-dough-linkmanager-link-type="file"]').first().val()).to.equal('bar.pdf');
    });
  });

  describe('Publish link', function () {
    beforeEach(function (done) {
      this.component = new this.LinkManager(this.$fixture);
      this.component.init();
      done();
    });

    it('should publish the link variable and emitter ID via the events bus', function() {
      var spy = sandbox.spy(),
          link = 'http://www.foo.com';

      this.eventsWithPromises.subscribe('linkmanager:link-published', spy);

      this.component.setLink('internal', link);
      this.component.publishLink(link);

      expect(spy.args[0][0].link).to.equal(link);
      expect(spy.args[0][0].emitter).to.equal('add-link');
    });
  });

  describe('Track the currently selected link', function () {
    beforeEach(function (done) {
      this.component = new this.LinkManager(this.$fixture);
      this.component.init();
      done();
    });

    it('should set the link variable', function() {
      var link = 'http://foo.com';

      this.component.setLink('internal', link);
      expect(this.component.linkValues['internal']).to.eq(link);
    });
  });

  describe('Get a link from the linkValues hash', function () {
  describe('getLink() Get a link from the linkValues hash', function () {
    beforeEach(function (done) {
      this.component = new this.LinkManager(this.$fixture);
      this.component.init();
      done();
    });
    it('should return the correct link based type', function() {
      var link = 'http://foo.com';

      this.component.setLink('internal', link);
      expect(this.component.getLink('internal')).to.equal(link);
    });
  });

  describe('Closing the dialog', function () {
    beforeEach(function (done) {
      this.component = new this.LinkManager(this.$fixture);
      this.component.init();
      done();
    });

    it('should call the changeTab and clearInputs to reset the view', function() {
      var changeTabSpy = sandbox.spy(this.LinkManager.prototype, 'changeTab'),
          clearInputsSpy = sandbox.spy(this.LinkManager.prototype, 'clearInputs');

      this.component.close();

      expect(changeTabSpy.calledWith('internal')).to.be.true;
      expect(clearInputsSpy.called).to.be.true;
    });
  });

});
<|endoftext|>


<commit_before>function Array1DTracer() {
    return Array2DTracer.apply(this, arguments);
}

Array1DTracer.prototype = $.extend(true, Object.create(Array2DTracer.prototype), {
    constructor: Array1DTracer,
    _notify: function (idx, v) {
        Array2DTracer.prototype._notify.call(this, 0, idx, v);
        return this;
    },
    _denotify: function (idx) {
        Array2DTracer.prototype._denotify.call(this, 0, idx);
        return this;
    },
    _select: function (s, e) {
        if (e === undefined) {
            Array2DTracer.prototype._select.call(this, 0, s);
        } else {
            Array2DTracer.prototype._selectRow.call(this, 0, s, e);
        }
        return this;
    },
    _deselect: function (s, e) {
        if (e === undefined) {
            Array2DTracer.prototype._deselect.call(this, 0, s);
        } else {
            Array2DTracer.prototype._deselectRow.call(this, 0, s, e);
        }
        return this;
    },
    setData: function (D) {
        return Array2DTracer.prototype.setData.call(this, [D]);
    }
});

var Array1D = {
    random: function (N, min, max) {
        return Array2D.random(1, N, min, max)[0];
    },
    randomSorted: function (N, min, max) {
        return Array2D.randomSorted(1, N, min, max)[0];
    }
};<commit_msg>add _separate/_deseparate methods in array1d<commit_after>function Array1DTracer() {
    return Array2DTracer.apply(this, arguments);
}

Array1DTracer.prototype = $.extend(true, Object.create(Array2DTracer.prototype), {
    constructor: Array1DTracer,
    _notify: function (idx, v) {
        Array2DTracer.prototype._notify.call(this, 0, idx, v);
        return this;
    },
    _denotify: function (idx) {
        Array2DTracer.prototype._denotify.call(this, 0, idx);
        return this;
    },
    _select: function (s, e) {
        if (e === undefined) {
            Array2DTracer.prototype._select.call(this, 0, s);
        } else {
            Array2DTracer.prototype._selectRow.call(this, 0, s, e);
        }
        return this;
    },
    _deselect: function (s, e) {
        if (e === undefined) {
            Array2DTracer.prototype._deselect.call(this, 0, s);
        } else {
            Array2DTracer.prototype._deselectRow.call(this, 0, s, e);
        }
        return this;
    },
    _separate: function (idx) {
        this.manager.pushStep(this.capsule, {
            type: 'separate',
            x: 0,
            y: idx
        });
        return this;
    },
    _deseparate: function (idx) {
        this.manager.pushStep(this.capsule, {
            type: 'deseparate',
            x: 0,
            y: idx
        });
        return this;
    },
    setData: function (D) {
        return Array2DTracer.prototype.setData.call(this, [D]);
    }
});

var Array1D = {
    random: function (N, min, max) {
        return Array2D.random(1, N, min, max)[0];
    },
    randomSorted: function (N, min, max) {
        return Array2D.randomSorted(1, N, min, max)[0];
    }
};<|endoftext|>


<commit_before>// Combat attack module.
var Cattack = (function()
{
    var attackBox;      //Display for attack.

    var attackState;    //State of the attack.
    var ATTACK_STATE = Object.freeze(
    {
        HIT : 0,        //State when dealing damage.
        SMASH : 1,      //State when showing smash effect.
        DAMAGE : 2,     //State when displaying damage.
        DELAY : 3,      //Delay after everything else is done.
    });

    var attackBars;             //Bars representing each attack.
    var attackFades;            //Bars representing each fade effect where an attack occured.
    var attackBoxOpacity;       //Opacity of the attack box visual.
    var totalDamage;            //Total damage dealt by attacks.
    var delayCounter;           //Counter for duration delay.
    var delay;                  //Duration delay.

    var healthTemp;
    var healthBarPos;
    var healthBarWidth;
    var healthBarVel;
    var healthTextPos;
    var healthTextVel;
    var healthTextAcc;

    //Init
    function init()
    {
        attackBox = document.getElementById("attack_box");
    }

    //Setup
    function setup()
    {
        attackBars = [37, 0 - Math.random() * 75];                  //First two attack bars.
        attackBars.push(attackBars[1] - 30 - Math.random() * 75);   //Second attack bar based on the first.
        attackFades = [];
        attackState = ATTACK_STATE.HIT;
        attackBoxOpacity = 1;
        totalDamage = 0;

        healthTemp = Cgroup.getCurHP(Combat.getSelectStateEnemy());
        healthBarWidth = Cgroup.getMaxHP(Combat.getSelectStateEnemy());
        healthBarPos = Cgroup.getDamagePos(Combat.getSelectStateEnemy()).get();
        healthBarPos.x -= healthBarWidth / 2;
        healthBarVel = 70;
        healthTextPos = Cgroup.getDamagePos(Combat.getSelectStateEnemy()).get();
        healthTextPos.y -= 32;
        healthTextVel = -160;
        healthTextAcc = 500;
    }

    //Update
    function update(dt)
    {
        switch(attackState)
        {
            case ATTACK_STATE.HIT:
                //Z button to deal an attack. Attacks are based on and consume an attack bar.
                if(myKeys.keydown[myKeys.KEYBOARD.KEY_Z])
                {
                    //Attack
                    var hit = attackBars[0];                                         //Hit at attack bar position.
                    var damage = Math.max(0, 282 - Math.abs(hit - 312)); //Damage based on hit.
                    if(damage > 280)            //Crit
                    {
                        damage *= 1.5;          //Crit multiplier
                        attackFades.push([hit, 1, 1]);
                    }
                    else                        //Normal hit
                    {
                        attackFades.push([hit, 0, 1]);
                    }
                    damage = Math.floor(damage);

                    totalDamage += damage;      //Increment damage

                    attackBars.splice(0, 1);    //Remove the consumed attack bar.

                    //Sfx for attack.
                    if(attackBars.length > 0)
                    {
                        if(damage < 280)
                            Sound.playSound("hit_1", true);
                        else
                            Sound.playSound("hit_1_crit", true);
                    }
                    else
                    {
                        if(damage < 280)
                            Sound.playSound("hit_2", true);
                        else
                            Sound.playSound("hit_2_crit", true);
                    }
                }

                //Go to damage state if no attacks are left or if the attacks are beyond the canvas.
                if(attackBars.length < 1 || attackBars[attackBars.length - 1] > 640)
                {
                    delayCounter = 0;
                    delay = 1.2;
                    attackState = ATTACK_STATE.SMASH;
                }

                //Update attack bar positions.
                for (var i = 0; i < attackBars.length; i++)
                {
                    attackBars[i] += 240 * dt;
                }
                break;
            case ATTACK_STATE.SMASH:
                attackBoxOpacity -= 2 * dt; //Fade out the attack box.
                delayCounter += dt;
                if(attackBoxOpacity < 0)    //Force attack box opacity to be 0 once it reaches 0.
                {
                    attackBoxOpacity = 0;
                }
                if(delayCounter > delay)
                {
                    totalDamage = totalDamage.toString();
                    for(var i = 0; i < totalDamage.length; i++)
                    {
                        if(totalDamage.charAt(i) == 1)
                            healthTextPos.x -= 10;
                        else
                            healthTextPos.x -= 16;
                    }
                    Cgroup.dealDamage(Combat.getSelectStateEnemy(), totalDamage);
                    Sound.playSound("impact", true);
                    attackState = ATTACK_STATE.DAMAGE
                }
                break;
            case ATTACK_STATE.DAMAGE:
                healthTextVel += healthTextAcc * dt;
                healthTextPos.y += healthTextVel * dt;
                if(healthTextPos.y > healthBarPos.y - 32 && healthTextVel > 0)
                {
                    healthTextPos.y = healthBarPos.y - 32;
                    healthTextVel = 0;
                    healthTextAcc = 0;
                }

                healthTemp -= healthBarVel * dt;
                if(healthTemp < Cgroup.getCurHP(Combat.getSelectStateEnemy()))
                {
                    delayCounter = 0;
                    delay = .5;
                    attackState = ATTACK_STATE.DELAY;
                }
                break;
            case ATTACK_STATE.DELAY:
                delayCounter += dt;
                if(delayCounter > delay)
                {
                    return true;
                }
                break;
        }

        //Update attack fade effects regardless of state.
        for (var i = 0; i < attackFades.length; i++)
        {
            attackFades[i][2] -= 2 * dt;
            if(attackFades[i][2] < 0)
            {
                attackFades[i][2] = 0;
            }
        }

        //Return the totalDamage dealt.
        return false;
    }

    //Draw
    function draw(ctx)
    {
        //Draw the attack box.
        ctx.save();
        ctx.globalAlpha = attackBoxOpacity;
        ctx.drawImage(
            attackBox,
            37,
            255);
        ctx.restore();

        //Draw everything else.
        ctx.save();
        switch(attackState)
        {
            case ATTACK_STATE.HIT:
                //Draw attack bars.
                ctx.lineWidth = 4;
                for (var i = 0; i < attackBars.length; i++)
                {
                    if(i)   //Attack bars > 1 colors.
                    {
                        ctx.strokeStyle = "#FFF";
                        ctx.fillStyle = "#000";
                    }
                    else    //Attack bar 0 color.
                    {
                        ctx.strokeStyle = "#000";
                        ctx.fillStyle = "#FFF";
                    }

                    //Draw bar.
                    ctx.beginPath();
                    ctx.rect(attackBars[i], 258, 14, 125);
                    ctx.fill();
                    ctx.stroke();
                }
                break;
            case ATTACK_STATE.SMASH:
                break;
            case ATTACK_STATE.DELAY:
            case ATTACK_STATE.DAMAGE:
                ctx.fillStyle = "#404040";
                ctx.strokeStyle = "#000";
                ctx.lineWidth = 1;
                ctx.beginPath();
                ctx.rect(
                    healthBarPos.x - .5,
                    healthBarPos.y - .5,
                    healthBarWidth,
                    15);
                ctx.fill();
                ctx.stroke();
                ctx.fillStyle = "#0F0";
                ctx.fillRect(
                    healthBarPos.x - .5,
                    healthBarPos.y - .5,
                    healthTemp,
                    15);
                var subPos = healthTextPos.get();
                for(var i = 0; i < totalDamage.length; i++)
                {
                    ctx.drawImage(
                        document.getElementById("d" + totalDamage.charAt(i)),
                        subPos.x,
                        subPos.y);

                    if(totalDamage.charAt(i) == 1)
                    {
                        subPos.x += 20;
                    }
                    else
                    {
                        subPos.x += 32;
                    }
                }
                break;
        }

        //Draw attack fades.
        for (var i = 0; i < attackFades.length; i++)
        {
            ctx.save();
            ctx.globalAlpha = attackFades[i][2];    //Fade fadeout

            //Set style of each fade.
            switch(attackFades[i][1])
            {
                case 0:     //Normal
                    ctx.fillStyle = "#0FF";
                    break;
                case 1:     //Crit
                    if(Math.floor(attackFades[i][2] * 6) % 2)   //Flash between Green and Orange
                        ctx.fillStyle = "#F80";
                    else
                        ctx.fillStyle = "#0F0";
                    break;
            }

            //Draw fade
            ctx.beginPath();
            ctx.rect(
                attackFades[i][0] - (1 - attackFades[i][2]) * 5,
                258 - (1 - attackFades[i][2]) * 40,
                14 + (1 - attackFades[i][2]) * 10,
                125 + (1 - attackFades[i][2]) * 80);
            ctx.fill();
            ctx.restore();
        }
        ctx.restore();
    }

    //Module return.
    return {
        init : init,
        setup : setup,
        update : update,
        draw : draw
    }
}());<commit_msg>Fixed damage text bounce ending prematurely.<commit_after>// Combat attack module.
var Cattack = (function()
{
    var attackBox;      //Display for attack.

    var attackState;    //State of the attack.
    var ATTACK_STATE = Object.freeze(
    {
        HIT : 0,        //State when dealing damage.
        SMASH : 1,      //State when showing smash effect.
        DAMAGE : 2,     //State when displaying damage.
        DELAY : 3,      //Delay after everything else is done.
    });

    var attackBars;             //Bars representing each attack.
    var attackFades;            //Bars representing each fade effect where an attack occured.
    var attackBoxOpacity;       //Opacity of the attack box visual.
    var totalDamage;            //Total damage dealt by attacks.
    var delayCounter;           //Counter for duration delay.
    var delay;                  //Duration delay.

    var healthTemp;
    var healthBarPos;
    var healthBarWidth;
    var healthBarVel;
    var healthTextPos;
    var healthTextVel;
    var healthTextAcc;

    //Init
    function init()
    {
        attackBox = document.getElementById("attack_box");
    }

    //Setup
    function setup()
    {
        attackBars = [37, 0 - Math.random() * 75];                  //First two attack bars.
        attackBars.push(attackBars[1] - 30 - Math.random() * 75);   //Second attack bar based on the first.
        attackFades = [];
        attackState = ATTACK_STATE.HIT;
        attackBoxOpacity = 1;
        totalDamage = 0;

        healthTemp = Cgroup.getCurHP(Combat.getSelectStateEnemy());
        healthBarWidth = Cgroup.getMaxHP(Combat.getSelectStateEnemy());
        healthBarPos = Cgroup.getDamagePos(Combat.getSelectStateEnemy()).get();
        healthBarPos.x -= healthBarWidth / 2;
        healthBarVel = 70;
        healthTextPos = Cgroup.getDamagePos(Combat.getSelectStateEnemy()).get();
        healthTextPos.y -= 32;
        healthTextVel = -160;
        healthTextAcc = 500;
    }

    //Update
    function update(dt)
    {
        switch(attackState)
        {
            case ATTACK_STATE.HIT:
                //Z button to deal an attack. Attacks are based on and consume an attack bar.
                if(myKeys.keydown[myKeys.KEYBOARD.KEY_Z])
                {
                    //Attack
                    var hit = attackBars[0];                                         //Hit at attack bar position.
                    var damage = Math.max(0, 282 - Math.abs(hit - 312)); //Damage based on hit.
                    if(damage > 280)            //Crit
                    {
                        damage *= 1.5;          //Crit multiplier
                        attackFades.push([hit, 1, 1]);
                    }
                    else                        //Normal hit
                    {
                        attackFades.push([hit, 0, 1]);
                    }
                    damage = Math.floor(damage);

                    totalDamage += damage;      //Increment damage

                    attackBars.splice(0, 1);    //Remove the consumed attack bar.

                    //Sfx for attack.
                    if(attackBars.length > 0)
                    {
                        if(damage < 280)
                            Sound.playSound("hit_1", true);
                        else
                            Sound.playSound("hit_1_crit", true);
                    }
                    else
                    {
                        if(damage < 280)
                            Sound.playSound("hit_2", true);
                        else
                            Sound.playSound("hit_2_crit", true);
                    }
                }

                //Go to damage state if no attacks are left or if the attacks are beyond the canvas.
                if(attackBars.length < 1 || attackBars[attackBars.length - 1] > 640)
                {
                    delayCounter = 0;
                    delay = 1.2;
                    attackState = ATTACK_STATE.SMASH;
                }

                //Update attack bar positions.
                for (var i = 0; i < attackBars.length; i++)
                {
                    attackBars[i] += 240 * dt;
                }
                break;
            case ATTACK_STATE.SMASH:
                attackBoxOpacity -= 2 * dt; //Fade out the attack box.
                delayCounter += dt;
                if(attackBoxOpacity < 0)    //Force attack box opacity to be 0 once it reaches 0.
                {
                    attackBoxOpacity = 0;
                }
                if(delayCounter > delay)
                {
                    totalDamage = totalDamage.toString();
                    for(var i = 0; i < totalDamage.length; i++)
                    {
                        if(totalDamage.charAt(i) == 1)
                            healthTextPos.x -= 10;
                        else
                            healthTextPos.x -= 16;
                    }
                    Cgroup.dealDamage(Combat.getSelectStateEnemy(), totalDamage);
                    Sound.playSound("impact", true);
                    attackState = ATTACK_STATE.DAMAGE
                }
                break;
            case ATTACK_STATE.DAMAGE:
                healthTextVel += healthTextAcc * dt;
                healthTextPos.y += healthTextVel * dt;
                if(healthTextPos.y > healthBarPos.y - 32 && healthTextVel > 0)
                {
                    healthTextPos.y = healthBarPos.y - 32;
                    healthTextVel = 0;
                    healthTextAcc = 0;
                }

                healthTemp -= healthBarVel * dt;
                if(healthTemp < Cgroup.getCurHP(Combat.getSelectStateEnemy()) && !healthTextAcc)
                {
                    delayCounter = 0;
                    delay = .5;
                    attackState = ATTACK_STATE.DELAY;
                }
                break;
            case ATTACK_STATE.DELAY:
                delayCounter += dt;
                if(delayCounter > delay)
                {
                    return true;
                }
                break;
        }

        //Update attack fade effects regardless of state.
        for (var i = 0; i < attackFades.length; i++)
        {
            attackFades[i][2] -= 2 * dt;
            if(attackFades[i][2] < 0)
            {
                attackFades[i][2] = 0;
            }
        }

        //Return the totalDamage dealt.
        return false;
    }

    //Draw
    function draw(ctx)
    {
        //Draw the attack box.
        ctx.save();
        ctx.globalAlpha = attackBoxOpacity;
        ctx.drawImage(
            attackBox,
            37,
            255);
        ctx.restore();

        //Draw everything else.
        ctx.save();
        switch(attackState)
        {
            case ATTACK_STATE.HIT:
                //Draw attack bars.
                ctx.lineWidth = 4;
                for (var i = 0; i < attackBars.length; i++)
                {
                    if(i)   //Attack bars > 1 colors.
                    {
                        ctx.strokeStyle = "#FFF";
                        ctx.fillStyle = "#000";
                    }
                    else    //Attack bar 0 color.
                    {
                        ctx.strokeStyle = "#000";
                        ctx.fillStyle = "#FFF";
                    }

                    //Draw bar.
                    ctx.beginPath();
                    ctx.rect(attackBars[i], 258, 14, 125);
                    ctx.fill();
                    ctx.stroke();
                }
                break;
            case ATTACK_STATE.SMASH:
                break;
            case ATTACK_STATE.DELAY:
            case ATTACK_STATE.DAMAGE:
                ctx.fillStyle = "#404040";
                ctx.strokeStyle = "#000";
                ctx.lineWidth = 1;
                ctx.beginPath();
                ctx.rect(
                    healthBarPos.x - .5,
                    healthBarPos.y - .5,
                    healthBarWidth,
                    15);
                ctx.fill();
                ctx.stroke();
                ctx.fillStyle = "#0F0";
                ctx.fillRect(
                    healthBarPos.x - .5,
                    healthBarPos.y - .5,
                    healthTemp,
                    15);
                var subPos = healthTextPos.get();
                for(var i = 0; i < totalDamage.length; i++)
                {
                    ctx.drawImage(
                        document.getElementById("d" + totalDamage.charAt(i)),
                        subPos.x,
                        subPos.y);

                    if(totalDamage.charAt(i) == 1)
                    {
                        subPos.x += 20;
                    }
                    else
                    {
                        subPos.x += 32;
                    }
                }
                break;
        }

        //Draw attack fades.
        for (var i = 0; i < attackFades.length; i++)
        {
            ctx.save();
            ctx.globalAlpha = attackFades[i][2];    //Fade fadeout

            //Set style of each fade.
            switch(attackFades[i][1])
            {
                case 0:     //Normal
                    ctx.fillStyle = "#0FF";
                    break;
                case 1:     //Crit
                    if(Math.floor(attackFades[i][2] * 6) % 2)   //Flash between Green and Orange
                        ctx.fillStyle = "#F80";
                    else
                        ctx.fillStyle = "#0F0";
                    break;
            }

            //Draw fade
            ctx.beginPath();
            ctx.rect(
                attackFades[i][0] - (1 - attackFades[i][2]) * 5,
                258 - (1 - attackFades[i][2]) * 40,
                14 + (1 - attackFades[i][2]) * 10,
                125 + (1 - attackFades[i][2]) * 80);
            ctx.fill();
            ctx.restore();
        }
        ctx.restore();
    }

    //Module return.
    return {
        init : init,
        setup : setup,
        update : update,
        draw : draw
    }
}());<|endoftext|>


<commit_before>import { expect } from 'chai';
import { resolve } from '../../../lib';

describe('resolving loops: ordered-ordered', function () {
    it('should not throw error if detected loop on itself', function () {
        var decl = [{ block: 'A' }],
            deps = [{
                entity: { block: 'A' },
                dependOn: [{
                    entity: { block: 'A' },
                    order: 'dependenceBeforeDependants'
                }]
            }];

        expect(function () { resolve(decl, deps); }).to.not.throw();
    });

    it('should throw error if detected direct loop', function () {
        var decl = [
                { block: 'A' },
                { block: 'B' }
            ],
            deps = [
                {
                    entity: { block: 'A' },
                    dependOn: [
                        {
                            entity: { block: 'B' },
                            order: 'dependenceBeforeDependants'
                        }
                    ]
                },
                {
                    entity: { block: 'B' },
                    dependOn: [
                        {
                            entity: { block: 'A' },
                            order: 'dependenceBeforeDependants'
                        }
                    ]
                }
            ],
            error = null;

        try {
            resolve(decl, deps);
        } catch (e) {
            error = e;
        }
        expect(error.loop).to.be.deep.equal([
            { entity: { block: 'A' } },
            { entity: { block: 'B' } },
            { entity: { block: 'A' } }
        ]);
    });

    it('should throw error if detected indirect loop', function () {
        var decl = [
                { block: 'A' },
                { block: 'B' },
                { block: 'C' }
            ],
            deps = [
                {
                    entity: { block: 'A' },
                    dependOn: [
                        {
                            entity: { block: 'B' },
                            order: 'dependenceBeforeDependants'
                        }
                    ]
                },
                {
                    entity: { block: 'B' },
                    dependOn: [
                        {
                            entity: { block: 'C' },
                            order: 'dependenceBeforeDependants'
                        }
                    ]
                },
                {
                    entity: { block: 'C' },
                    dependOn: [
                        {
                            entity: { block: 'A' },
                            order: 'dependenceBeforeDependants'
                        }
                    ]
                }
            ],
            error = null;

        try {
            resolve(decl, deps);
        } catch (e) {
            error = e;
        }
        expect(error.loop).to.be.deep.equal([
            { entity: { block: 'A' } },
            { entity: { block: 'B' } },
            { entity: { block: 'C' } },
            { entity: { block: 'A' } }
        ]);
    });

    it('should throw error if detected intermediate loop', function () {
        var decl = [
                { block: 'A' },
                { block: 'B' },
                { block: 'C' }
            ],
            deps = [
                {
                    entity: { block: 'A' },
                    dependOn: [
                        {
                            entity: { block: 'B' },
                            order: 'dependenceBeforeDependants'
                        }
                    ]
                },
                {
                    entity: { block: 'B' },
                    dependOn: [
                        {
                            entity: { block: 'C' },
                            order: 'dependenceBeforeDependants'
                        }
                    ]
                },
                {
                    entity: { block: 'C' },
                    dependOn: [
                        {
                            entity: { block: 'B' },
                            order: 'dependenceBeforeDependants'
                        }
                    ]
                }
            ],
            error = null;

        try {
            resolve(decl, deps);
        } catch (e) {
            error = e;
        }
        expect(error.loop).to.be.deep.equal([
            { entity: { block: 'B' } },
            { entity: { block: 'C' } },
            { entity: { block: 'B' } }
        ]);
    });

    it('should throw error if detected direct entity - tech loop', function () {
        var decl = [
                { block: 'A' },
                { block: 'B' }
            ],
            deps = [
                {
                    entity: { block: 'A' },
                    dependOn: [
                        {
                            entity: { block: 'B' },
                            tech: 'css',
                            order: 'dependenceBeforeDependants'
                        }
                    ]
                },
                {
                    entity: { block: 'B' },
                    dependOn: [
                        {
                            entity: { block: 'A' },
                            order: 'dependenceBeforeDependants'
                        }
                    ]
                }
            ],
            opts = { tech: 'css' },
            error = null;

        try {
            resolve(decl, deps, opts);
        } catch (e) {
            error = e;
        }

        expect(error.loop).to.be.deep.equal([
            { entity: { block: 'A' } },
            { entity: { block: 'B' }, tech: 'css' },
            { entity: { block: 'A' } }
        ]);
    });

    it('should throw error if detected direct tech - entity loop', function () {
        var decl = [
                { block: 'A' },
                { block: 'B' }
            ],
            deps = [
                {
                    entity: { block: 'A' },
                    dependOn: [
                        {
                            entity: { block: 'B' },
                            order: 'dependenceBeforeDependants'
                        }
                    ]
                },
                {
                    entity: { block: 'B' },
                    dependOn: [
                        {
                            entity: { block: 'A' },
                            tech: 'css',
                            order: 'dependenceBeforeDependants'
                        }
                    ]
                }
            ],
            opts = { tech: 'css' },
            error = null;

        try {
            resolve(decl, deps, opts);
        } catch (e) {
            error = e;
        }

        expect(error.loop).to.be.deep.equal([
            { entity: { block: 'A' } },
            { entity: { block: 'B' } },
            { entity: { block: 'A' }, tech: 'css' }
        ]);
    });

    it('should not throw error if detected loop on itself and one of techs is matching with resolving ' +
        'tech', function () {
        var decl = [{ block: 'A' }],
            deps = [{
                entity: { block: 'A' },
                tech: 'css',
                dependOn: [{
                    entity: { block: 'A' },
                    tech: 'js',
                    order: 'dependenceBeforeDependants'
                }]
            }],
            opts = { tech: 'css' };

        expect(function () { resolve(decl, deps, opts); }).to.not.throw();
    });

    it('should throw error if detected direct loop and both techs are matching with resolving tech', function () {
        var decl = [
                { block: 'A' },
                { block: 'B' }
            ],
            deps = [
                {
                    entity: { block: 'A' },
                    tech: 'css',
                    dependOn: [
                        {
                            entity: { block: 'B' },
                            tech: 'css',
                            order: 'dependenceBeforeDependants'
                        }
                    ]
                },
                {
                    entity: { block: 'B' },
                    tech: 'css',
                    dependOn: [
                        {
                            entity: { block: 'A' },
                            tech: 'css',
                            order: 'dependenceBeforeDependants'
                        }
                    ]
                }
            ],
            opts = { tech: 'css' },
            error = null;

        try {
            resolve(decl, deps, opts);
        } catch (e) {
            error = e;
        }

        expect(error.loop).to.be.deep.equal([
            { entity: { block: 'A' }, tech: 'css' },
            { entity: { block: 'B' }, tech: 'css' },
            { entity: { block: 'A' }, tech: 'css' }
        ]);
    });

    it('should not throw error if detected direct loop and one of techs is not matching with resolving ' +
        'tech', function () {
        var decl = [
                { block: 'A' },
                { block: 'B' }
            ],
            deps = [
                {
                    entity: { block: 'A' },
                    tech: 'css',
                    dependOn: [
                        {
                            entity: { block: 'B' },
                            tech: 'js',
                            order: 'dependenceBeforeDependants'
                        }
                    ]
                },
                {
                    entity: { block: 'B' },
                    tech: 'css',
                    dependOn: [
                        {
                            entity: { block: 'A' },
                            tech: 'css',
                            order: 'dependenceBeforeDependants'
                        }
                    ]
                }
            ],
            opts = { tech: 'css' };

        expect(function () { resolve(decl, deps, opts); }).to.not.throw();
    });

    it('should not throw error if detected indirect loop and one of techs is not matching with resolving ' +
        'tech', function () {
        var decl = [
                { block: 'A' },
                { block: 'B' },
                { block: 'C' }
            ],
            deps = [
                {
                    entity: { block: 'A' },
                    tech: 'css',
                    dependOn: [
                        {
                            entity: { block: 'B' },
                            tech: 'css',
                            order: 'dependenceBeforeDependants'
                        }
                    ]
                },
                {
                    entity: { block: 'B' },
                    tech: 'css',
                    dependOn: [
                        {
                            entity: { block: 'C' },
                            tech: 'js',
                            order: 'dependenceBeforeDependants'
                        }
                    ]
                },
                {
                    entity: { block: 'C' },
                    tech: 'css',
                    dependOn: [
                        {
                            entity: { block: 'A' },
                            tech: 'css',
                            order: 'dependenceBeforeDependants'
                        }
                    ]
                }
            ],
            opts = { tech: 'css' };

        expect(function () { resolve(decl, deps, opts); }).to.not.throw();
    });

    it('should not throw error if detected intermediate loop and one of techs is matching with resolving ' +
        'tech', function () {
        var decl = [
                { block: 'A' },
                { block: 'B' }
            ],
            deps = [
                {
                    entity: { block: 'A' },
                    tech: 'css',
                    dependOn: [
                        {
                            entity: { block: 'B' },
                            tech: 'css'
                        }
                    ]
                },
                {
                    entity: { block: 'B' },
                    tech: 'css',
                    dependOn: [
                        {
                            entity: { block: 'C' },
                            tech: 'js',
                            order: 'dependenceBeforeDependants'
                        }
                    ]
                },
                {
                    entity: { block: 'C' },
                    tech: 'css',
                    dependOn: [
                        {
                            entity: { block: 'B' },
                            tech: 'css',
                            order: 'dependenceBeforeDependants'
                        }
                    ]
                }
            ];

        expect(function () { resolve(decl, deps); }).to.not.throw();
    });
});
<commit_msg>test: skip tests with error info<commit_after>import { expect } from 'chai';
import { resolve } from '../../../lib';

describe('resolving loops: ordered-ordered', function () {
    it('should not throw error if detected loop on itself', function () {
        var decl = [{ block: 'A' }],
            deps = [{
                entity: { block: 'A' },
                dependOn: [{
                    entity: { block: 'A' },
                    order: 'dependenceBeforeDependants'
                }]
            }];

        expect(function () { resolve(decl, deps); }).to.not.throw();
    });

    it('should throw error if detected direct loop', function () {
        var decl = [
                { block: 'A' },
                { block: 'B' }
            ],
            deps = [
                {
                    entity: { block: 'A' },
                    dependOn: [
                        {
                            entity: { block: 'B' },
                            order: 'dependenceBeforeDependants'
                        }
                    ]
                },
                {
                    entity: { block: 'B' },
                    dependOn: [
                        {
                            entity: { block: 'A' },
                            order: 'dependenceBeforeDependants'
                        }
                    ]
                }
            ],
            error = null;

        try {
            resolve(decl, deps);
        } catch (e) {
            error = e;
        }
        expect(error.loop).to.be.deep.equal([
            { entity: { block: 'A' } },
            { entity: { block: 'B' } },
            { entity: { block: 'A' } }
        ]);
    });

    it('should throw error if detected indirect loop', function () {
        var decl = [
                { block: 'A' },
                { block: 'B' },
                { block: 'C' }
            ],
            deps = [
                {
                    entity: { block: 'A' },
                    dependOn: [
                        {
                            entity: { block: 'B' },
                            order: 'dependenceBeforeDependants'
                        }
                    ]
                },
                {
                    entity: { block: 'B' },
                    dependOn: [
                        {
                            entity: { block: 'C' },
                            order: 'dependenceBeforeDependants'
                        }
                    ]
                },
                {
                    entity: { block: 'C' },
                    dependOn: [
                        {
                            entity: { block: 'A' },
                            order: 'dependenceBeforeDependants'
                        }
                    ]
                }
            ],
            error = null;

        try {
            resolve(decl, deps);
        } catch (e) {
            error = e;
        }
        expect(error.loop).to.be.deep.equal([
            { entity: { block: 'A' } },
            { entity: { block: 'B' } },
            { entity: { block: 'C' } },
            { entity: { block: 'A' } }
        ]);
    });

    it('should throw error if detected intermediate loop', function () {
        var decl = [
                { block: 'A' },
                { block: 'B' },
                { block: 'C' }
            ],
            deps = [
                {
                    entity: { block: 'A' },
                    dependOn: [
                        {
                            entity: { block: 'B' },
                            order: 'dependenceBeforeDependants'
                        }
                    ]
                },
                {
                    entity: { block: 'B' },
                    dependOn: [
                        {
                            entity: { block: 'C' },
                            order: 'dependenceBeforeDependants'
                        }
                    ]
                },
                {
                    entity: { block: 'C' },
                    dependOn: [
                        {
                            entity: { block: 'B' },
                            order: 'dependenceBeforeDependants'
                        }
                    ]
                }
            ],
            error = null;

        try {
            resolve(decl, deps);
        } catch (e) {
            error = e;
        }
        expect(error.loop).to.be.deep.equal([
            { entity: { block: 'B' } },
            { entity: { block: 'C' } },
            { entity: { block: 'B' } }
        ]);
    });

    it.skip('should throw error if detected direct entity - tech loop', function () {
        var decl = [
                { block: 'A' },
                { block: 'B' }
            ],
            deps = [
                {
                    entity: { block: 'A' },
                    dependOn: [
                        {
                            entity: { block: 'B' },
                            tech: 'css',
                            order: 'dependenceBeforeDependants'
                        }
                    ]
                },
                {
                    entity: { block: 'B' },
                    dependOn: [
                        {
                            entity: { block: 'A' },
                            order: 'dependenceBeforeDependants'
                        }
                    ]
                }
            ],
            opts = { tech: 'css' },
            error = null;

        try {
            resolve(decl, deps, opts);
        } catch (e) {
            error = e;
        }

        expect(error.loop).to.be.deep.equal([
            { entity: { block: 'A' } },
            { entity: { block: 'B' }, tech: 'css' },
            { entity: { block: 'A' } }
        ]);
    });

    it.skip('should throw error if detected direct tech - entity loop', function () {
        var decl = [
                { block: 'A' },
                { block: 'B' }
            ],
            deps = [
                {
                    entity: { block: 'A' },
                    dependOn: [
                        {
                            entity: { block: 'B' },
                            order: 'dependenceBeforeDependants'
                        }
                    ]
                },
                {
                    entity: { block: 'B' },
                    dependOn: [
                        {
                            entity: { block: 'A' },
                            tech: 'css',
                            order: 'dependenceBeforeDependants'
                        }
                    ]
                }
            ],
            opts = { tech: 'css' },
            error = null;

        try {
            resolve(decl, deps, opts);
        } catch (e) {
            error = e;
        }

        expect(error.loop).to.be.deep.equal([
            { entity: { block: 'A' } },
            { entity: { block: 'B' } },
            { entity: { block: 'A' }, tech: 'css' }
        ]);
    });

    it('should not throw error if detected loop on itself and one of techs is matching with resolving ' +
        'tech', function () {
        var decl = [{ block: 'A' }],
            deps = [{
                entity: { block: 'A' },
                tech: 'css',
                dependOn: [{
                    entity: { block: 'A' },
                    tech: 'js',
                    order: 'dependenceBeforeDependants'
                }]
            }],
            opts = { tech: 'css' };

        expect(function () { resolve(decl, deps, opts); }).to.not.throw();
    });

    it.skip('should throw error if detected direct loop and both techs are matching with resolving tech', function () {
        var decl = [
                { block: 'A' },
                { block: 'B' }
            ],
            deps = [
                {
                    entity: { block: 'A' },
                    tech: 'css',
                    dependOn: [
                        {
                            entity: { block: 'B' },
                            tech: 'css',
                            order: 'dependenceBeforeDependants'
                        }
                    ]
                },
                {
                    entity: { block: 'B' },
                    tech: 'css',
                    dependOn: [
                        {
                            entity: { block: 'A' },
                            tech: 'css',
                            order: 'dependenceBeforeDependants'
                        }
                    ]
                }
            ],
            opts = { tech: 'css' },
            error = null;

        try {
            resolve(decl, deps, opts);
        } catch (e) {
            error = e;
        }

        expect(error.loop).to.be.deep.equal([
            { entity: { block: 'A' }, tech: 'css' },
            { entity: { block: 'B' }, tech: 'css' },
            { entity: { block: 'A' }, tech: 'css' }
        ]);
    });

    it('should not throw error if detected direct loop and one of techs is not matching with resolving ' +
        'tech', function () {
        var decl = [
                { block: 'A' },
                { block: 'B' }
            ],
            deps = [
                {
                    entity: { block: 'A' },
                    tech: 'css',
                    dependOn: [
                        {
                            entity: { block: 'B' },
                            tech: 'js',
                            order: 'dependenceBeforeDependants'
                        }
                    ]
                },
                {
                    entity: { block: 'B' },
                    tech: 'css',
                    dependOn: [
                        {
                            entity: { block: 'A' },
                            tech: 'css',
                            order: 'dependenceBeforeDependants'
                        }
                    ]
                }
            ],
            opts = { tech: 'css' };

        expect(function () { resolve(decl, deps, opts); }).to.not.throw();
    });

    it('should not throw error if detected indirect loop and one of techs is not matching with resolving ' +
        'tech', function () {
        var decl = [
                { block: 'A' },
                { block: 'B' },
                { block: 'C' }
            ],
            deps = [
                {
                    entity: { block: 'A' },
                    tech: 'css',
                    dependOn: [
                        {
                            entity: { block: 'B' },
                            tech: 'css',
                            order: 'dependenceBeforeDependants'
                        }
                    ]
                },
                {
                    entity: { block: 'B' },
                    tech: 'css',
                    dependOn: [
                        {
                            entity: { block: 'C' },
                            tech: 'js',
                            order: 'dependenceBeforeDependants'
                        }
                    ]
                },
                {
                    entity: { block: 'C' },
                    tech: 'css',
                    dependOn: [
                        {
                            entity: { block: 'A' },
                            tech: 'css',
                            order: 'dependenceBeforeDependants'
                        }
                    ]
                }
            ],
            opts = { tech: 'css' };

        expect(function () { resolve(decl, deps, opts); }).to.not.throw();
    });

    it('should not throw error if detected intermediate loop and one of techs is matching with resolving ' +
        'tech', function () {
        var decl = [
                { block: 'A' },
                { block: 'B' }
            ],
            deps = [
                {
                    entity: { block: 'A' },
                    tech: 'css',
                    dependOn: [
                        {
                            entity: { block: 'B' },
                            tech: 'css'
                        }
                    ]
                },
                {
                    entity: { block: 'B' },
                    tech: 'css',
                    dependOn: [
                        {
                            entity: { block: 'C' },
                            tech: 'js',
                            order: 'dependenceBeforeDependants'
                        }
                    ]
                },
                {
                    entity: { block: 'C' },
                    tech: 'css',
                    dependOn: [
                        {
                            entity: { block: 'B' },
                            tech: 'css',
                            order: 'dependenceBeforeDependants'
                        }
                    ]
                }
            ];

        expect(function () { resolve(decl, deps); }).to.not.throw();
    });
});
<|endoftext|>


<commit_before>var listObjects = require('./listObjects.js');
var conn;
function init(connection){
    if (!connection && !this.conn) this.conn = require('../ForceConnection.js').connection;
    else { conn = connection;}
    listObjects.init(conn);
}

function execute(){
    var promise = new Promise(function(resolve, reject){
        if(!conn) {reject('Invalid Force.com connection');}

        var results = [];
        function isCustomObject(value){
            if(String(value.name).indexOf('__c') > -1) {return value;}
        }
        listObjects.execute()
            .then(
                function(x){
                    results = x.map(isCustomObject)
                               .filter(function(n){ return n != undefined });

                    var pendingDescribes = results.map(function(x) {
                        var describePromise = new Promise(function(resolve, reject) {
                            console.log('Getting: '+x.name);
                            conn.sobject(x.name).describe(function(err, meta) {
                                if (err) { reject(err); }
                                console.log('returning: '+meta);
                                resolve(meta);
                            });
                        });

                        return describePromise;
                    });

                    Promise.all(pendingDescribes).then(function(values) {
                        resolve(values);
                    });
                }
            )
    });

    return promise;
}

exports.init = init;
exports.execute = execute;<commit_msg>Cleaned up listing of custom objects (full describe)<commit_after>var listObjects = require('./listObjects.js');
var conn;
function init(connection){
    if (!connection && !this.conn) this.conn = require('../ForceConnection.js').connection;
    else { conn = connection;}
    listObjects.init(conn);
}

function isCustomObject(value){
    if(String(value.name).indexOf('__c') > -1) {return value;}
}

function execute(){
    var promise = new Promise(function(resolve, reject){
        if(!conn) {reject('Invalid Force.com connection');}

        var results = [];

        listObjects.execute()
            .then(function(obj){
                results = obj.map(isCustomObject)
                           .filter(function(n){ return n != undefined });

                var pendingDescribes = results.map(function(x) {
                    var describePromise = new Promise(function(resolve, reject) {
                        conn.sobject(x.name).describe$(function(err, meta) {
                            if (err) { reject(err); }
                            resolve(meta);
                        });
                    });

                    return describePromise;
                });

                Promise.all(pendingDescribes).then(function(values) {
                    resolve(values);
                });
            }
        )
    });

    return promise;
}

exports.init = init;
exports.execute = execute;<|endoftext|>


<commit_before>/* Copyright 2015 Realm Inc - All Rights Reserved
 * Proprietary and Confidential
 */

'use strict';

import Realm from 'realm';

export default new Realm({
    schema: [
        {
            name: 'Todo',
            properties: {
                done: {type: Realm.Types.BOOL, default: false},
                text: Realm.Types.STRING,
            },
        },
        {
            name: 'TodoList',
            properties: {
                name: Realm.Types.STRING,
                items: {type: Realm.Types.LIST, objectType: 'Todo', default: []},
            },
        },
    ],
});
<commit_msg>use classes in the examples<commit_after>/* Copyright 2015 Realm Inc - All Rights Reserved
 * Proprietary and Confidential
 */

'use strict';

import Realm from 'realm';

class Todo {}
Todo.schema = {
    name: 'Todo',
    properties: {
        done: {type: Realm.Types.BOOL, default: false},
        text: Realm.Types.STRING,
    },
};
class TodoList {}
TodoList.schema = {
    name: 'TodoList',
    properties: {
        name: Realm.Types.STRING,
        items: {type: Realm.Types.LIST, objectType: 'Todo', default: []},
    },
};
export default new Realm({schema: [Todo, TodoList]});
<|endoftext|>


<commit_before>/** @constructor */
var i$VM = function() {
  this.valstack = {};
  this.valstack_top = 0;
  this.valstack_base = 0;

  this.ret = null;

  this.callstack = [];
}

var i$vm;
var i$valstack;
var i$valstack_top;
var i$valstack_base;
var i$ret;
var i$callstack;

var i$Int = {};
var i$String = {};
var i$Integer = {};
var i$Float = {};
var i$Char = {};
var i$Ptr = {};
var i$Forgot = {};

/** @constructor */
var i$CON = function(tag,args,app,ev) {
  this.tag = tag;
  this.args = args;
  this.app = app;
  this.ev = ev;
}

/** @constructor */
var i$POINTER = function(addr) {
  this.addr = addr;
}

var i$SCHED = function(vm) {
  i$vm = vm;
  i$valstack = vm.valstack;
  i$valstack_top = vm.valstack_top;
  i$valstack_base = vm.valstack_base;
  i$ret = vm.ret;
  i$callstack = vm.callstack;
}

var i$SLIDE = function(args) {
  for (var i = 0; i < args; ++i)
    i$valstack[i$valstack_base + i] = i$valstack[i$valstack_top + i];
}

var i$PROJECT = function(val,loc,arity) {
  for (var i = 0; i < arity; ++i)
    i$valstack[i$valstack_base + i + loc] = val.args[i];
}

var i$CALL = function(fun,args) {
  i$callstack.push(args);
  i$callstack.push(fun);
}

var i$ffiWrap = function(fid,oldbase,myoldbase) {
  return function() {
    var oldstack = i$callstack;
    i$callstack = [];

    var res = fid;

    for(var i = 0; i < (arguments.length ? arguments.length : 1); ++i) {
      while (res instanceof i$CON) {
        i$valstack_top += 1;
        i$valstack[i$valstack_top] = res;
        i$valstack[i$valstack_top + 1] = arguments[i];
        i$SLIDE(2);
        i$valstack_top = i$valstack_base + 2;
        i$CALL(_idris__123_APPLY0_125_,[oldbase])
        while (i$callstack.length) {
          var func = i$callstack.pop();
          var args = i$callstack.pop();
          func.apply(this,args);
        }
        res = i$ret;
      }
    }

    i$callstack = oldstack;

    return i$ret;
  }
}

var i$charCode = function(str) {
  if (typeof str == "string")
    return str.charCodeAt(0);
  else
    return str;
}

var i$fromCharCode = function(chr) {
  if (typeof chr == "string")
    return chr;
  else
    return String.fromCharCode(chr);
}

var i$RUN = function () {
  for (var i = 0; i < 1000 && i$callstack.length; i++) {
    var func = i$callstack.pop();
    var args = i$callstack.pop();
    func.apply(this,args);
  };

  if (i$callstack.length)
    setTimeout(i$RUN, 0);
}
<commit_msg>javascript: tweak event scheduling<commit_after>/** @constructor */
var i$VM = function() {
  this.valstack = {};
  this.valstack_top = 0;
  this.valstack_base = 0;

  this.ret = null;

  this.callstack = [];
}

var i$vm;
var i$valstack;
var i$valstack_top;
var i$valstack_base;
var i$ret;
var i$callstack;

var i$Int = {};
var i$String = {};
var i$Integer = {};
var i$Float = {};
var i$Char = {};
var i$Ptr = {};
var i$Forgot = {};

/** @constructor */
var i$CON = function(tag,args,app,ev) {
  this.tag = tag;
  this.args = args;
  this.app = app;
  this.ev = ev;
}

/** @constructor */
var i$POINTER = function(addr) {
  this.addr = addr;
}

var i$SCHED = function(vm) {
  i$vm = vm;
  i$valstack = vm.valstack;
  i$valstack_top = vm.valstack_top;
  i$valstack_base = vm.valstack_base;
  i$ret = vm.ret;
  i$callstack = vm.callstack;
}

var i$SLIDE = function(args) {
  for (var i = 0; i < args; ++i)
    i$valstack[i$valstack_base + i] = i$valstack[i$valstack_top + i];
}

var i$PROJECT = function(val,loc,arity) {
  for (var i = 0; i < arity; ++i)
    i$valstack[i$valstack_base + i + loc] = val.args[i];
}

var i$CALL = function(fun,args) {
  i$callstack.push(args);
  i$callstack.push(fun);
}

var i$ffiWrap = function(fid,oldbase,myoldbase) {
  return function() {
    var oldstack = i$callstack;
    i$callstack = [];

    var res = fid;

    for(var i = 0; i < (arguments.length ? arguments.length : 1); ++i) {
      while (res instanceof i$CON) {
        i$valstack_top += 1;
        i$valstack[i$valstack_top] = res;
        i$valstack[i$valstack_top + 1] = arguments[i];
        i$SLIDE(2);
        i$valstack_top = i$valstack_base + 2;
        i$CALL(_idris__123_APPLY0_125_,[oldbase])
        while (i$callstack.length) {
          var func = i$callstack.pop();
          var args = i$callstack.pop();
          func.apply(this,args);
        }
        res = i$ret;
      }
    }

    i$callstack = oldstack;

    return i$ret;
  }
}

var i$charCode = function(str) {
  if (typeof str == "string")
    return str.charCodeAt(0);
  else
    return str;
}

var i$fromCharCode = function(chr) {
  if (typeof chr == "string")
    return chr;
  else
    return String.fromCharCode(chr);
}

var i$RUN = function () {
  for (var i = 0; i < 10000 && i$callstack.length; i++) {
    var func = i$callstack.pop();
    var args = i$callstack.pop();
    func.apply(this,args);
  };

  if (i$callstack.length)
    setTimeout(i$RUN, 0);
}
<|endoftext|>