How to convert config/environment.js to CoffeeScript? - ember-cli

Using ember-cli version 0.2.3, I converted config/environment.js to config/environment.coffee.
The app is named frontend.
In the dist/frontend.js file, I see the following differences - note that instead of frontend, the prefix is undefined.
How to fix this?
Working:
define('frontend/config/environment', ['ember'], function(Ember) {
var prefix = 'frontend';
...
Not working:
define('undefined/config/environment', ['ember'], function(Ember) {
var prefix = 'undefined';
...

Related

babel is not using .babelrc. Why?

I am trying to learn babel. I got the babel-core module working, but I am trying to use .babelrc and it's not doing anything.
Here's my .babelrc file.
{
"plugins":["transform-es3-property-literals"]
}
And here's my code:
var babel = require("babel-core");
var js = `var x = { catch: 4, bar: 7 };`;
var notUsingBabelRc = babel.transform(js,{
plugins: ["transform-es3-property-literals"]
}).code;
var usingBabelRc = babel.transform(js).code
console.log(notUsingBabelRc == usingBabelRc);
//false, but should be true. Adding plugins as an option transforms the code.
console.log(usingBabelRc == js);
//true, but should be false. The code is not changed from its original form.
I have the .babelrc file in the root directory of the project. I also have my script file called using_babelrc.js a the root directory of the project.
Then I call node using_babelrc and I get false true even though I expect true false.
What simple thing am I missing?
The transform function also needs the filename option supplied to start looking for .babelrc files relative to that filename. In your case:
babel.transform(js, {filename: "using_babelrc.js"}).code;
will read the config file in the same folder as using_babelrc.js.

Using Trello REST in Ionic 2 - Error TS2304 Cannot find name 'Trello'

being a newbee to the ionic 2 and Trello REST interface I need help please:
As per the Trello.com site (https://developers.trello.com/get-started/start-building) I have:
Added under the html line in the index.html ie: before the body as they ask, the following and replaced the AppKey in my code:
< script src="http://code.jquery.com/jquery-1.7.1.min.js"></script>
< script src="https://api.trello.com/1/client.js?key=[AppKey]"></script>
Added code to add a card as per their example:
var myList = 'myIDLIST';
var creationSuccess = function(data) {
console.log('Card created successfully. Data returned:' + JSON.stringify(data));
};
var newCard = {
name: 'New Test Card',
desc: 'This is the description of our new card.',
// Place this card at the top of our list
idList: myList,
pos: 'top'
};
Trello.post('/cards/', newCard, creationSuccess);
However I get a typescript error:
TypeScript error: C:/workspace/...etc..../service.ts(66,9): Error TS2304: Cannot find name 'Trello'.
I thought Trello should be available to other modules since its declared in the index.html
Any help appreciated.
The Trello object might exist at runtime, but the Typescript compiler doesn't know about it, so it reports the errors. You have to provide the declaration files or simply tell the compiler that it should expect a global Trello object. For that put this line of code to the beginning of every file that uses the Trello object.
declare var Trello: any;
You can also use the node-trello package and import it directly.

Cloud9 & Meteor.js undefined global var

I'm trying to create the Leaderboard on Cloud9. But I get the error: PlayersList not defined... in the editor. The app is working, but then it's code in editor underlining all 'not defind PlayersList'
The code:
PlayersList = new Mongo.Collection('players');
if(Meteor.isClient){
Template.leaderboard.helpers({
'player': function(){
return PlayersList.find({}, {sort: {score: -1, name: 1}});
},
'selectedClass': function(){
var playerId = this._id;
var selectedPlayer = Session.get('selectedPlayer');
if(selectedPlayer === playerId){
return 'selected';
}
},
'showSelectedPlayer': function(){
var selectedPlayer = Session.get('selectedPlayer');
return PlayersList.findOne(selectedPlayer);
}
});
Cloud9's editor uses ESLint, and using foo = 22 makes it think that there's a missing statement like var foo; somewhere. You can either choose to ignore this, or fix it as follows:
Add /*eslint-env meteor */ to the top so it doesn't give warnings about Meteor globals, and maybe you'll also need to add /* globals Player */ added too in case the error still stays. (I haven't tested this out, please let me know how it goes so I can improve the answer)
I solved the problem with a little workaround. I added coffeescript and then I used the # symbol on the global like you should, when you define a collection with coffeescript. And that was solving it for me. It works fine. As I opened the app in an new browser window, posts were available in the console.
Example:
#Posts = new Mongo.Collection('posts')

Collection.update giving server error

Trying to learn the Meteor framework as well as coffeescript/node all at once. Been working on a simple file upload program that utilizes onloadend. When the FileReader onloadend event function is called I try to determine if the file already exists and if so I update with the new file data and version.
The code works for insert but not update. Can someone help? I've posted to meteor-talk w/o an answer as I suspect its the weekend (when I do most of my experimentation).
Code snippet...
file_reader.onloadend = ((file_event) ->
(event) ->
f_filename = escape file_event.name
version = 0
f_record = null
f_record = doc_repo.findOne { name: f_filename }
if f_record && f_record.name
doc_repo.update
name: f_filename
,
$set:
version: 10
else
doc_repo.insert
name: f_filename
data: event.target.result
version: 0
)(file_obj)
Error
Exception while invoking method '/documents/update' TypeError: Cannot read property 'toBSON' of undefined
at Function.calculateObjectSize (/usr/local/meteor/lib/node_modules/mongodb/node_modules/bson/lib/bson/bson.js:210:12)
at BSON.calculateObjectSize (/usr/local/meteor/lib/node_modules/mongodb/node_modules/bson/lib/bson/bson.js:1463:15)
at UpdateCommand.toBinary (/usr/local/meteor/lib/node_modules/mongodb/lib/mongodb/commands/update_command.js:67:20)
at Connection.write (/usr/local/meteor/lib/node_modules/mongodb/lib/mongodb/connection/connection.js:138:40)
at __executeInsertCommand (/usr/local/meteor/lib/node_modules/mongodb/lib/mongodb/db.js:1837:14)
at Db._executeInsertCommand (/usr/local/meteor/lib/node_modules/mongodb/lib/mongodb/db.js:1912:7)
at Collection.update (/usr/local/meteor/lib/node_modules/mongodb/lib/mongodb/collection.js:445:13)
at app/packages/mongo-livedata/mongo_driver.js:178:16
at Db.collection (/usr/local/meteor/lib/node_modules/mongodb/lib/mongodb/db.js:507:44)
at _Mongo._withCollection (app/packages/mongo-livedata/mongo_driver.js:51:13)
It looks like Mongo is not getting the second parameter which it needs to do the update. So in regular JavaScript it's expecting this:
collection.update({..selector..}, { .. modifier });
So I'd try putting some curly brackets around the modifier object, like this:
doc_repo.update
name: f_filename,
{
$set:
version: 10
}

Playframework 2.0 define function in View Template

I am working on a project using PlayFramework 2.0. After reading a bit of scala I would like to embed some dynamic code in the View template. So, I did the following:
#{
def getMystring(sequence:Int) = {
if(patternForm != null &&
patternForm.get().windowTreatments != null &&
patternForm.get().windowTreatments.size() >= sequence + 1)
sequence+""
else
""
}
}
<input type = "text" value = #getMystring(1)></input>
...
I was quite sure it was going to work but instead I got a "not found: value getMyString Error occurred" . Did I do something obviously wrong?
try starting it like a template, like this
#getMystring(sequence:Int) = {
[...]
have a look at https://github.com/playframework/Play20/blob/master/samples/scala/computer-database/app/views/list.scala.html
The problem being that play defines a very narrow scope and can't recognize defs outside its current curly brackets.
You can change the position of the last curly bracket for your def to include the input tag and then it should work.
Or you can do what opensas suggested.
#getMystring(sequence:Int) = {
[...]