Learn TypeScript by building a Reddit Api Client

TypeScript is seeing increasing adoption across the developer community. According to the Stack Overflow Developer Survey 2022 TypeScript ranks 3rd as the ‘Most Wanted’ programming language by developers.

It’s time for me to get up to speed and considering TypeScript is a superset of JavaScript the learning curve should be OK for me!

The best way to learn is to do right? With that in mind I’ve started a project to build a TypeScript Reddit Api Client. It’s pretty simple. You install the npm module and you can use it to interact with the Reddit API.

Now there is an official Reddit node module which last time I looked was written with JavaScript. So why not create a TypeScript version for learning?

Variety is the spice of life.

If you are interested in learning TypeScript feel free to catch up with me here.

Find out more here

Learn ES6 with Katas

One of my colleagues pointed me in the direction of this great JavaScript ES6 learning resource.

es6katas.org/

Working my way through the ES6 katas.

There’s ES5, ES6, then ES7, TypeScript, AtScript, Dart, Babel…the list goes on

 

WTF is ES6?

Javascript as browsers understand it is a bit like the “assembly of the web,” meaning that it can correctly run code that was implemented in a higher level language and “compiled” down to JS the browser understands.

 

MongoDB for Node.js Developers Course

MongoDB University

Recently I completed the MongoDB for Node.js Developers Course from (MongoDB University)[https://university.mongodb]. This is my experience..

Course Overview

It’s a 7 week online course that covers using mongoDB and Node.js. Each week you’ll have 20 – 30 short (5 to 10 minute) video lessons followed by a quiz. The quiz can be multiple choice or writing javascript + mongoDB queries.
The quiz results do not count towards the final grade.
At the end of each week there is a homework assignment to complete and submit for verification.

Expect to spend ~3 hours on lessons and other couple on homework per week. It can be challenging to keep up the momentum of 7 weeks.

Grading

The homework assignments from each week will make up 50% of your final grade. The other 50% for a final exam.
65% is the overall grade you’ll need to hit to pass. Upon passing you’ll get a ‘cert’ from MonogoDB University. I’m expecting to receive mine in the next few weeks. After christmas 🙂

Course Structure

  • Week 1: Introduction – Installing, mongo shell, installing tools, node modules, swig, express
  • Week 2: CRUD – Mongo shell, queries, update, operators etc
  • Week 3: Patterns, case studies, trade offs
  • Week 4: Performance – indexes, monitoring, sharding
  • Week 5: Aggregation Framework – pipeline, SQL comparisons
  • Week 6: Replication and sharding
  • Week 7: Intro to Mongoose and FINAL EXAM

Conclusion

Worth it.
I came to this course with little knowledge of MongoDb. I had done several tutorials + read a couple of books.

However through the lessons, quizzes, homework etc, I picked up a decent bit of practical experience and theoretical knowledge for getting up and running. And if I’m luckily …for scaling out.

Also did I mention it’s a free course?

Tutorial 4: Sencha Weather App – OpenWeatherMap Api + Model + Store

Register on OpenWeatherMap

OpenWeatherMap provides a handy api for guess what? That’s right weather reports. Follow the steps to register and get a URL endpoint.

  1. Register at: http://openweathermap.org/API
  2. Click Free API
  3. Click ‘more’ under ‘Get Current Weather Data’

This is the default example:

api.openweathermap.org/data/2.5/weather?q=London,uk

We have some options to format the data coming back:

api.openweathermap.org/data/2.5/weather?units=metric&q=Dublin, IE

See the JSON response with Dublin related weather reports. This will do for the moment.

Next add the weather API to our Sencha app.

In keeping with best practice we will add this configuration to the app.js in our app root. Seems like a good place of it.

In time I will want to make the location configurable so I’ve broken into two variables. Plus a variable for the location of the images the openweathermap kindly provide.

 /* configuration openweathermap API */
    weatherAPI: 'http://api.openweathermap.org/data/2.5/weather?units=metric&q=',
    defaultCountry: 'Dublin,ie',
    openweatherimages: 'http://openweathermap.org/img/w/',

Model

The model will describe the shape of the data. We’ll shape the data we get back from the above URL.

1) Create the model file app/model/Weather.js
The names on the field array are taken form the JSON response.

Ext.define('WeatherApp.model.Weather', {
    extend: 'Ext.data.Model',
    config: {
        fields: ['name', 'main', 'country', 'sys', 'weather']
    }
});

API JSON response:

{"coord":{"lon":-6.26719,"lat":53.34399},"sys":{"country":"IE","sunrise":1372132698,"sunset":1372193845},"weather":[{"id":803,"main":"Clouds","description":"broken clouds","icon":"04d"}],"base":"global stations","main":{"temp":18.4,"humidity":58,"pressure":1028,"temp_min":18,"temp_max":18.89},"wind":{"speed":4.63,"gust":4.63,"deg":247},"clouds":{"all":80},"dt":1372179878,"id":2964574,"name":"Dublin","cod":200}

Our model object will have attributes name, main, country, sys, weather. We can pull the data from the object via these attributes.

But we need to get the data in to the model in the first place. Enter stores.

Oh yes, we’ll need to add our model to our app.js, as we previously did with views.

A store for Weather

In the previous tutorial we hooked up a view to the Weather store.  But we didn’t create the store. We’ll do that now:

app/store/Weather.js

Ext.define('WeatherApp.store.Weather', {
    extend: 'Ext.data.Store',

    config: {
        model: 'WeatherApp.model.Weather',
        //autoLoad: true,
        proxy: {
            type: 'jsonp',
            url : WeatherApp.app.weatherAPI + WeatherApp.app.defaultCountry,
            reader: {
                type: 'json'
            }
        }
    }
});

THE NEXT STEPs FOR US:

  • A new tab panel for location
  • An input field to allow the user to enter a location.
  • Model and store to save the location to local storage.
  • A controller to manage the interactions between the view and the store.

CODE HERE:

https://github.com/jamiegood/WeatherApp/tree/InputWeatherLocation

Sencha Touch BDD series from Pivotal Labs

A great series of blog posts on Behavior Driven Development(BDD) with Sencha Touch. Covers BDD with Jasmine Javascript tests to test Sencha Touch models, stores and controllers. Covers mocking and also running tests via phantom.js.

Thanks pivotal labs