CoffeeScript functions - coffeescript

I was reading this smooth CoffeeScript book and it had a code
confirm 'Shall we, then?', (answer) -> show answer
This is supposed to get the answer from the confirm and show it / I changed the 'show' to console.log and it doesn't seem to execute it. what am I missing.
thanks

confirm() doesn't take a callback. Unless this guy made his own confirm function, that won't work. The cs for that compiles to
confirm("Shall we, then?", function(answer) {
return console.log(answer);
});
confirm() returns true or false, so you can just use it as a conditional.
console.log "They answered yes" if confirm "Shall we, then?"

Related

Protractor element.click() throwing an exception

I was trying to figure out why .click() below was crashing protractor :
this.clickSecondPanel = function () {
element(by.css('div.panels-gs.panel-top-two-gs')).click();
}
until I changed the line to :
element(by.css('div.panels-gs.panel-top-two-gs')).click;
where my spec.js looks something like :
var DataCardPage = require('./pageObjects/dataCard.page.js');
var dataCardPage = new DataCardPage();
describe('Clicking on the 2nd panel', function () {
dataCardPage.clickSecondPanel();
it('Should select the 2nd test panel', function () {
expect(dataCardPage.getSecondPanelText()).toBe('TEST123');
});
In other places in my code, I use .click() (with parenths), so this is confusing to me.
The error is nasty:
Started
[17:44:23] E/launcher - Error while waiting for Protractor to sync with the page
: "window.angular is undefined. This could be either because this is a non-angu
lar page or because your test involves client-side navigation, which can interfe
re with Protractor's bootstrapping. See http://git.io/v4gXM for details"
Any advice appreciated...
Bob
Solved this in the comments above, posting as an answer.
My suggestion was to try moving the clickSecondPanel() inside the it block. It looked suspicious by itself just from a "best practice" perspective as I do not have any code that is outside of a jasmine function i.e. it, beforeAll, afterAll etc (don't even know where I learned that habit honestly).
It also seemed to effect the control flow and asynchronous execution so the click() event was triggering too soon. This can be explained in part by this documentation and/or this blog post
Try using browser.ignoreSynchronization=true at the begining of your test. May be the application that you are trying to automated does not contain angular in it.

What do I return from my Gulp task if I decide to do nothing?

Suppose my gulp task decides to do nothing -- what should I return?
gulp.task 'maybe_transform_files', ->
if check_something()
gulp.src('src')
.pipe transform_files()
.pipe gulp.dest('target')
else
return something
In other situations, I might use the done() callback, but I don't think I can use it here, where I might return a stream.
An old post, but no extra node package required now. gulp.src('.') should work just fine, as #Nick Perkins mentioned.
have a look at gulp-nop
what you can do to have no-op is
var nop = require('gulp-nop');
.....
return gulp.src('.').pipe(nop());
or if you are using gulp-util you can use noop, similarly

How significant is the order with jQuery's trigger-method?

I want to provide a way to use an on-event handler from the outside of a plugin. Problem is, that the trigger will not fired if I provide them in wrong order.
For example, this works:
$(window).on('foo:bar', function(){
alert(true);
});
$(window).trigger('foo:bar');
...this, however does not:
$(window).trigger('foo:bar');
$(window).on('foo:bar', function(){
alert(true);
});
Any ideas how the second approach can work?
Update
Here it works: http://www.benplum.com/projects/rubberband/
You cannot. You want to eat cake before baking it.
UPD: You're misinterpreting the code at http://www.benplum.com/projects/rubberband/
Here is a jsfiddle with proof that it doesn't work like you're thinking: jsfiddle.net/zerkms/z5Mya/
Note about code: I've forked the library and added trivial console.log here: https://github.com/zerkms/Rubberband/blob/master/jquery.bp.rubberband.js#L77

Editor.isDirty() broken?

The Editor.isDirty() does not seem to be working correctly. In our application we check the Editor.isDirty() flag. When it evaluates to true we need to move forward with some actions. If nothing has changed we don't want to waste processor time evaluating data that hasn't changed. In our case once the content is updated once isDirty() always evaluates to true. Even when nothing has changed.
The Editor.isDirty() function seems pretty simple:
isDirty : function() {
var self = this;
return tinymce.trim(self.startContent) != tinymce.trim(self.getContent({format : 'raw', no_events : 1})) && !self.isNotDirty;
}
The key seems to be the startContent property. That's what TinyMCE uses to determine a change has occured. Therefore I would expect this property to be updated when save() is called on the Editor. Looking through the code shows this does not happen. In fact startContent does is not reset anywhere which would support it's use here. Has anyone else seen this behavior, or am I using the Editor object incorrectly?
sidenote: TinyMCE version 3.5.7.

How to enable msg and debug logging with Log::Message::Simple

I'm using Log::Message::Simple and error()s appear immediately. However, calls to debug() and msg() do nothing -- I have to call Log::Message::Simple->stack_as_string() to get these. How can I get this logging to appear immediately?
I'm not sure that this is the best solution, but I've fixed this by specifying the optional 'verbose' parameter to msg() and debug(), for example
msg("my message", 1);
For the stack_as_string, I thought you had to enable the flag.
Log::Message::Simple->stack_as_string(1);
HTH