coffeescript

Defer Angular UI Router $stateChangeStart until server authorization response receieved

我与影子孤独终老i 提交于 2019-12-29 05:57:31
问题 I have an Angular app using UI Router where I'm trying to validate a user's token, if one exists, when the app runs. I am also checking that the user has permission to access certains routes. The problem is that $stateChangeStart is running before I receive the response back from the authorization endpoint. Here's some code (coffeescript with js below) - this is all within my run block. app.run(($rootScope, $state, $stateParams, $log, Auth) -> currentState = 'home' $rootScope.$state = $state

CoffeeScript Undefined

允我心安 提交于 2019-12-28 08:04:00
问题 In javascript to check if a variable was never created, we just do if (typeof MyVariable !== "undefined"){ ... } I was wonder how I do that in coffeescript?... I try something like if (MyVariable?false){ ... } but this check if MyVariable is a function if so that will call MyVariable(false) if not that will call void(0) or something like that. 回答1: Finally I found this easy way to do it: if (MyVariable?){ ... } that will generate: if (typeof MyVariable !== "undefined" && MyVariable !== null){

using grunt, is it possible to compile and output a single changed file to a different directory?

时间秒杀一切 提交于 2019-12-25 16:43:44
问题 Many coffee source files in /assets/src/coffee etc ( ./child/paths and so on) and I'd like to output them to assets/js/ and assets/js/child/paths . It looks like I've gotten close, but it's not working. Using grunt-contrib-coffee and grunt-contrib-watch . grunt.initConfig watch: coffee: files: '<%= coffee.src %>', tasks: 'coffee:dev' options: nospawn: true coffee: src: 'assets/src/coffee/**/*.coffee' dev: options: sourceMap: true files: [ expand: true cwd: "assets/" src: "/src/coffee/**/*

How to stop Coffeescript from escaping keywords?

99封情书 提交于 2019-12-25 14:20:08
问题 I am trying to write a indexeddb function "delete". It should read like this in JS: var transaction = db.transaction('objectStore','readwrite'); var objectStore = transaction.objectStore('objectStore'); objectStore.delete(id); However, when I write it in CS: transaction = db.transaction 'objectStore','readWrite' objectStore = transaction.objectStore 'objectStore' objectStore.delete(id) Of course it outputs: ... objectStore["delete"](id); I didn't write a method for IDBTransaction called

Access $(this) DOM element from within jQuery Autocomplete Widget Ajax call

冷暖自知 提交于 2019-12-25 10:16:04
问题 In the code below (Coffeescript), in the AJAX call for the jQuery autocomplete data source, On line 5 of the code, I am passing 2 params - term: and ll: For ll: I'm trying to get $(this) to be the DOM element that .autocomplete was applied to. In this case its $('[type="text"][name*="[location]"]') I need to reference that DOM element specifically with ($this) on line 5. However, I believe 'this' at that scope refers to something else that isn't a DOM element. Can someone please help explain

How to mock calls to JQuery without including JQuery in my spec file at all

北慕城南 提交于 2019-12-25 09:05:55
问题 The function I want to test is mostly pure JavaScript (CoffeeScript), but includes one line that calls Jquery: $("input##{name}").change -> I don't want to include Jquery in my Jasmine files at all. I'd like to mock it out completely so this is a pure unit test. My spec for this function includes the following: class $ change: () -> return spy = spyOn($, 'change') However, Jasmine is giving me this error: Error: change() method does not exist How can I mock out $('input##{name}').change ->

Meteor path helper not returning anything

こ雲淡風輕ζ 提交于 2019-12-25 08:57:48
问题 to learn meteor, I'm following Sacha Greif's book 'Discovering Meteor'. The current source code is reflected here-> https://github.com/stopachka/meteor-hackernews Right now, I'm trying to add a 'discuss' link to the post_item, which is supposed to render the single post_item. <template name="postItem"> <div class="post"> <div class="post-content"> <h3><a href="{{url}}">{{title}}</a><span>{{domain}}</span></h3> </div> <a href="{{postPagePath title}}" class="discuss btn">Discuss</a> </div> <

Wrap all CoffeScript files in a JQuery document ready function after concatenation?

社会主义新天地 提交于 2019-12-25 07:24:49
问题 I have a number of CoffeeScript files which I concatenate using a Cakefile before converting to Javascript. How do I wrap the concatenated CoffeScript file with a JQuery on document ready function? For example: I have the following CoffeScript files each containing a Class: foo.coffee bar.coffee tea.coffee To produce the JS file I use the following Cake command to concatente the coffee and produce the JS: task 'build', 'Build single application file from source files', -> appContents = new

Gmaps4rails looping through array

╄→гoц情女王★ 提交于 2019-12-25 06:54:56
问题 I have an array with 30+ locations I would like to display on my map. However, I have not found one source that demonstrates how to iterate through an array so that the markers appear on a map, but instead opt to strictly hard code the map lat/long values. For example, this is the code I have at present but it returns errors: allLocations = root.table.rows().data() root.forMap = [] for aLocation in allLocations root.forMap.push(aLocation[9] + ', ' + aLocation[10]) $('#multi_markers').map ->

Calling an action inside render in ReactJS - cannot dispatch in the middle of dispatch

邮差的信 提交于 2019-12-25 06:31:13
问题 I'm dealing with searching for public and private accounts on Instagram. To give a brief context, I'm trying to query all the users on Instagram but since I don't have access to target_user_is_private (our submitted app doesn't have the follower_list scope) I'm just going to check for the state's data id and approach it that way. I'm getting an issue of "Cannot dispatch in the middle of dispatch" with the code below - what is the solution to this problem? render: () -> if !@state.data.id