From 538af0796f9e0a081f5aa88bf778d8090c4884a5 Mon Sep 17 00:00:00 2001 From: Dave Allen Date: Thu, 29 Aug 2013 09:32:23 -0700 Subject: [PATCH 1/7] Minor change to intro --- meteor/README.md | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/meteor/README.md b/meteor/README.md index 9ea635d452..3226bd8eec 100644 --- a/meteor/README.md +++ b/meteor/README.md @@ -1,6 +1,11 @@ #Meteor Type Definitions Usage Notes -In order to effectively write your Meteor app with TypeScript, there are a few extra things you will need to do in addition to simply referencing the Meteor type definition file and renaming all of your *.js files to *.ts (which alone will not work). +In order to effectively write your Meteor app with TypeScript, you will probably need to follow these steps: + +- Reference the type definitions file +- Create a Templates definitions file +- Create Collections within modules + ##Referencing Meteor type definitions in your app - Place the meteor.d.ts file in a directory (maybe `/lib/typescript`) @@ -23,6 +28,7 @@ This will make these typed Meteor variables/objects available across your applic *Please note that the Template variable is not automatically available. You need to follow the instructions below to use the Template variable.* + ##Defining Templates In order to call `Template.yourTemplateName.method`, you will need to create a simple TypeScript definition file that declares a Template variable containing a list of template view-models/managers of type IMeteorViewModel (or IMeteorManager, which is the same as IMeteorViewModel). A good place for this definition could be `/client/views/view-model-types.d.ts`. Here is an example of that file: From 692bbb95e2103613a5473a1b339f58c77a845ebc Mon Sep 17 00:00:00 2001 From: Dave Allen Date: Thu, 29 Aug 2013 09:42:34 -0700 Subject: [PATCH 2/7] Minor change to intro --- meteor/README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/meteor/README.md b/meteor/README.md index 3226bd8eec..f501dcf54e 100644 --- a/meteor/README.md +++ b/meteor/README.md @@ -1,9 +1,9 @@ #Meteor Type Definitions Usage Notes -In order to effectively write your Meteor app with TypeScript, you will probably need to follow these steps: +In order to effectively write your Meteor app with TypeScript, you will probably need to do these things: -- Reference the type definitions file -- Create a Templates definitions file +- Reference the Meteor type definitions file (meteor.d.ts) +- Create a Template definition file - Create Collections within modules From 9e716b9bcc2b1949c85241bd3594d17b77b3e623 Mon Sep 17 00:00:00 2001 From: Dave Allen Date: Thu, 29 Aug 2013 09:43:15 -0700 Subject: [PATCH 3/7] Minor change to intro --- meteor/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/meteor/README.md b/meteor/README.md index f501dcf54e..092eaf02f0 100644 --- a/meteor/README.md +++ b/meteor/README.md @@ -1,6 +1,6 @@ #Meteor Type Definitions Usage Notes -In order to effectively write your Meteor app with TypeScript, you will probably need to do these things: +In order to effectively write a Meteor app with TypeScript, you will probably need to do these things: - Reference the Meteor type definitions file (meteor.d.ts) - Create a Template definition file From c13b2ed733cbb0b4d435d0c8eb9d647537a811e1 Mon Sep 17 00:00:00 2001 From: Dave Allen Date: Thu, 29 Aug 2013 09:50:05 -0700 Subject: [PATCH 4/7] Various changes to README --- meteor/README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/meteor/README.md b/meteor/README.md index 092eaf02f0..b2320b54fc 100644 --- a/meteor/README.md +++ b/meteor/README.md @@ -48,7 +48,7 @@ In order to call `Template.yourTemplateName.method`, you will need to create a s header: IMeteorViewModel; } -After you create this file, you may access the Template variable by declaring something like `/// ` at the top of any TypeScript file containing references to Template. Something like `Template.postsList.helpers()` would then transpile successfully (and have the benefits of typing). +After you create this file, you may access the Template variable by declaring something similar to `/// ` at the top of any TypeScript file containing references to Template. Something like `Template.postsList.helpers()` would then transpile successfully (and also have the benefits of typing). ##Defining Collections @@ -60,7 +60,7 @@ In TypeScript, global variables are not allowed, and in a Meteor app, creating a this.PostsModel = PostsModel; -You can then access the Posts collection by placing `/// ` at the top of a TypeScript file. The code would look like this: +You can then access the Posts collection by placing something similar to `/// ` at the top of a TypeScript file. The code within the file something would look something like this: PostsModel.Posts.findOne(Session.get('currentPostId')); From 3a99f271962955c985c7f3b22322251c05e6ddb3 Mon Sep 17 00:00:00 2001 From: Dave Allen Date: Tue, 3 Sep 2013 12:45:18 -0700 Subject: [PATCH 5/7] Changed section on collections --- meteor/README.md | 30 +++++++++++++++++++++++------- 1 file changed, 23 insertions(+), 7 deletions(-) diff --git a/meteor/README.md b/meteor/README.md index b2320b54fc..6ca88263d9 100644 --- a/meteor/README.md +++ b/meteor/README.md @@ -4,7 +4,7 @@ In order to effectively write a Meteor app with TypeScript, you will probably ne - Reference the Meteor type definitions file (meteor.d.ts) - Create a Template definition file -- Create Collections within modules +- Create Collections within a module or modules ##Referencing Meteor type definitions in your app @@ -52,17 +52,33 @@ After you create this file, you may access the Template variable by declaring so ##Defining Collections -In TypeScript, global variables are not allowed, and in a Meteor app, creating a local variable (using `var `) limits a variable's scope to the file. However, you will probably want to define variables, such as collections, that can be used across files. In the case of collections, one way to work around these limitations is to wrap each collection within a module, and then make the module globally accessible. Here is an example using posts.ts: +In TypeScript, global variables are not allowed, and in a Meteor app, creating a local variable (using `var `) limits a variable's scope to the file. However, you will probably want to define variables, such as collections, that can be used across files. In the case of collections, one way to work around these limitations is to wrap the definitions of all collections within a module, and then make the module globally accessible. Here is an example (collections/models.ts): - module PostsModel { + module Models { export var Posts = new Meteor.Collection('posts'); - }; + export var Comments = new Meteor.Collection('comments'); + export var Notifications = new Meteor.Collection('notifications'); - this.PostsModel = PostsModel; + export var createCommentNotification = function (comment) { + var post = Posts.findOne(comment.postId); + Notifications.insert({ + userId: post.userId, + postId: post._id, + commentId: comment._id, + commenterName: comment.author, + read: false + }); + }; -You can then access the Posts collection by placing something similar to `/// ` at the top of a TypeScript file. The code within the file something would look something like this: + } - PostsModel.Posts.findOne(Session.get('currentPostId')); + this.Models = Models; + +You can then access the Posts collection by placing something similar to `/// ` at the top of a TypeScript file. The code within the file something would look something like this: + + Models.Posts.findOne(Session.get('currentPostId')); + +For organizational purposes, any additional code related to each Collection can be placed in a separate file per each collection. Alternatively, you could wrap each collection in its own module (e.g. PostsModel for posts, CommentsModel for comments). ##Reference app From d6fe70c01b55aa3bae724a71a79bc6bbc7cfbfa7 Mon Sep 17 00:00:00 2001 From: Dave Allen Date: Tue, 3 Sep 2013 12:55:11 -0700 Subject: [PATCH 6/7] Minor changes to section on collections --- meteor/README.md | 16 ++-------------- 1 file changed, 2 insertions(+), 14 deletions(-) diff --git a/meteor/README.md b/meteor/README.md index 6ca88263d9..0c3fbe07a6 100644 --- a/meteor/README.md +++ b/meteor/README.md @@ -52,29 +52,17 @@ After you create this file, you may access the Template variable by declaring so ##Defining Collections -In TypeScript, global variables are not allowed, and in a Meteor app, creating a local variable (using `var `) limits a variable's scope to the file. However, you will probably want to define variables, such as collections, that can be used across files. In the case of collections, one way to work around these limitations is to wrap the definitions of all collections within a module, and then make the module globally accessible. Here is an example (collections/models.ts): +In TypeScript, global variables are not allowed, and in a Meteor app, creating a local variable (using `var `) limits a variable's scope to the file. However, you will probably want to define variables, such as collections, that can be used across multiple files. In the case of collections, one way to work around these limitations is to wrap the definitions of all collections within a module, and then make the module globally accessible. Here is an example (collections/models.ts): module Models { export var Posts = new Meteor.Collection('posts'); export var Comments = new Meteor.Collection('comments'); export var Notifications = new Meteor.Collection('notifications'); - - export var createCommentNotification = function (comment) { - var post = Posts.findOne(comment.postId); - Notifications.insert({ - userId: post.userId, - postId: post._id, - commentId: comment._id, - commenterName: comment.author, - read: false - }); - }; - } this.Models = Models; -You can then access the Posts collection by placing something similar to `/// ` at the top of a TypeScript file. The code within the file something would look something like this: +You can then access the Posts collection by placing something similar to `/// ` at the top of a TypeScript file. The code within the file would look something like this: Models.Posts.findOne(Session.get('currentPostId')); From 16db4e7088a13c354fe866e2f7dfdfc1ed8b36c7 Mon Sep 17 00:00:00 2001 From: Dave Allen Date: Tue, 3 Sep 2013 14:15:47 -0700 Subject: [PATCH 7/7] Minor changes to section on collections --- meteor/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/meteor/README.md b/meteor/README.md index 0c3fbe07a6..a654e86da9 100644 --- a/meteor/README.md +++ b/meteor/README.md @@ -70,7 +70,7 @@ For organizational purposes, any additional code related to each Collection can ##Reference app -A simple Meteor reference application created with TypeScript is listed below. It is based on the Microscope reference app in [Discover Meteor](http://www.discovermeteor.com/ "http://www.discovermeteor.com/"). +Listed below is a simple Meteor reference application created with TypeScript is listed below. It is based on the Microscope reference app in [Discover Meteor](http://www.discovermeteor.com/ "http://www.discovermeteor.com/"). - Sample Site: - Code (TypeScript and transpiled JS):