coffeescript

Mongoose document update error

大憨熊 提交于 2019-12-24 01:26:01
问题 Been working with node and mongoose lately and I enjoyed it until I had to update a model. Here is what I'm doing: module.exports.update = (post, cb) -> Post.update _id: post._id, post, (err, data) -> cb(err, data) So I thought it'll be a easy as saving a new post but it's complaining with error: err: 'Mod on _id not allowed' I tried to delete post._id before passing it to my update method, but it didn't work and I couldn't find any good examples on how to do it except one that looks a bit

backbone + rails TypeError: List.Header is not a constructor

别来无恙 提交于 2019-12-24 01:08:59
问题 I am trying to follow along with the tutorial I purchased from this site: http://www.backbonerails.com/ I am following along with the 5th episode of the series, "Getting Up and Running - Part 1". At about the 46:52 mark of the video he has this code for "list_controller.js.coffee". @Demo.module "HeaderApp.List", (List, App, Backbone, Marionette, $, _) -> List.Controller = listHeader: -> console.log "header" When I have this...everything works...the console reads "header". At about the 47:20

Just can't get Passport.js to work

北城余情 提交于 2019-12-24 00:47:12
问题 edit: sorry it's so long now, added in the compiled JS! I also added Kevs suggestions. I am developing a MEAN stack application (MongoDB, ExpressJS, Angular, NodeJS) and having a good time with it, especially with coffee script. My issue is that I can't get passport.js to work, every time it returns {success: false}. When I do a console.log in my LocalStrategy function it seems it's never even being called. Any idea why? Some snippets server.coffee (main file) ... Account = mongoose.model

coffeescript always returns

点点圈 提交于 2019-12-24 00:31:28
问题 So I have what's probably a stupid question to ask about Coffee Script. I'm giving it a second chance but why does it return everything ? Is it anything to do with being the last statement/line of the function? and how do I disable this? Putting a comment or something as the final "expression", I know it's a "documented" feature but no; no it's not really, how do I not have returns everywhere ? and save download/execution times? Surely this behaviour kind of screws the jit over? (locate =

Shared JS (Coffee) in Rails

旧巷老猫 提交于 2019-12-23 22:40:03
问题 If I want to share some JavaScript function between different files under app/assets/javascript what would be the best way to I organise the directory structure? Let's say I have shared.js.coffee sharedFunction = -> 'Hello ' Now, how can I use it in some other place? Like here, in welcome.js.coffee welcome = (name) -> sharedFunction() + name How can I make shared.js.cofee always be loaded first ? I tried to put it in the very beginning of application.js , but it doesn't change anything. Seems

Coffeescript: invoking function with space before parens

旧街凉风 提交于 2019-12-23 19:34:06
问题 When I invoke a function with a space before the parens, it gives an error saying unepected , sum = (a, b) -> a+b console.log (sum (1, 2)) error: unexpected , console.log (sum (1, 2)) it points to the comma between 1 and 2 Why the odd behavior? 回答1: In CoffeeScript you can write function calls in two ways: foo(bar) # with parens foo bar # without parens Since you have a space between sum and (1, 2) , then you are making a unparenthesized functional call of sum passing (1, 2) as the first

Gulp Filter with SourceMaps

时光怂恿深爱的人放手 提交于 2019-12-23 17:53:58
问题 I had a similar question here that has merged into a bit more research on my part and a new way this could work. Basically I'm trying to have all of my .js and .coffee files within one gulp.src() object and based on the extension, do relevant tasks. What started off with gulp-if has turned into me using gulp-filter which I prefer honestly. The catch I'm running into right now is getting this all to work with gulp-sourcemaps. The current task seems to override the other -- but I'd ultimately

CoffeeScript Intellisense

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-23 17:27:29
问题 I use Visual Studio for development and I am quite used to Intellisense. But when writting CoffeeScript you don't really get any Syntax Checking or Intellisense. Is there a plugin for VS that would allow this? Thanks 回答1: You can't have more than syntax checking/coloring with coffeescript (on any IDE) AFAIK. As an alternative, you can use TypeScript to get the full Visual Studio tooling support (and stay close to the javascript), or some transcompilers that transform code to javascript, for C

Simple promise example with bluebird and coffeescript works half the time

一笑奈何 提交于 2019-12-23 16:08:22
问题 So I'm basically attempting to write some simple code using promises and I'm having a bit of trouble understanding why this particular code works every other time. Promise = require('bluebird') mkdirp = Promise.promisify(require('mkdirp')) rm = Promise.promisify(require('rimraf')) console.log "Preparing build directory" rm('build') .then(mkdirp('build')) This will complete successfully the first run, but the second will fail, and so on. Here is the steps: ┌[adam@bigboi] [/dev/pts/5] [master ⚡

nodejs readers/writers concurrency

我的梦境 提交于 2019-12-23 15:29:41
问题 Here's some simple code that demonstrates what I'm trying to do myVar = 1 reader = () -> getDataFromServer1().then -> # uses myVar and does stuff according to its value # returns promise writer = () -> getDataFromServer2().then -> # assigns to myVar # returns promise Q.all([reader(), reader(), reader(), writer(), writer(), writer()]).done -> console.log 'done' So I have multiple threads running at the same time. some of them change the value of myVar and some read the value and rely on it.