Wisdom, TypeScript, Backbone and Polymer
Yesterday, I made my first steps with Wisdom (http://k33g.github.io/2014/07/13/WISDOM.html) and my conclusion was: βI think Iβve found THE Best Candidate to serve my Single Page Applicationsβ, so today I decided to play further away with my new toy.
Iβm going to change my previous sample and rewrite it with TypeScript, Backbone and Polymer. I love TypeScript because it allows to write code in a similar way of thinking as EcmaScript 6 (itβs my belief).
So, youβve to read http://k33g.github.io/2014/07/13/WISDOM.html
Add TypeScript support to Wisdom
Itβs very easy, there is already a plugin for this. Add this to your pom.xml
file:
TypeScript definitions
Now we need TypeScript definitions for Backbone, Underscore and jQuery. Definitions allow TypeScript to use existing JavaScript frameworks (a kind of contract).
We need to install tsd first, type this command: sudo npm install tsd -g
(see https://github.com/DefinitelyTyped/tsd for more details) and go to src/main/resources/assets
and type tsd query backbone underscore jquery --action install
.
tsd will create a sub-directories typings
with 3 TypeScript definitions:
assets/
βββ typings/
| βββ backbone/
| | βββ backbone.d.ts
| βββ underscore/
| | βββ underscore.d.ts
| βββ jquery/
| βββ jquery.d.ts
Add Backbone (and Underscore)
In src/main/resources/assets
directory, type bower install backbone --save
(it updates your bower.json
file) and donβt forget to add this to index.thl.html
:
You can now run your project: mvn wisdom:run
And now TypeScript coding!
in assets
directory, create a models
directory with a new file Entities.ts
:
assets/
βββ typings/
βββ models/
| βββ Entities.ts
|
And put this content in the Entities.ts
file:
Weβve just created a Backbone Model and a BackBone Collection.
Update ou WebComponent
assets/
βββ typings/
βββ models/
| βββ Entities.ts
βββ components/
| βββ humans-list.html
|
Yesterday, the content of humans-list.html
was like that:
Today, change it like that:
And add a humans-list.ts
file at the same location than humans-list.html
:
assets/
βββ typings/
βββ models/
| βββ Entities.ts
βββ components/
| βββ humans-list.html
| βββ humans-list.ts
|
with this content:
When you save your files, Wisdom will transpile all .ts
files to JavaScript.
You can refresh http://localhost:9000/, youβve got the same result as yesterday, but with TypeScript. And youβve gained the ability to write classes and modules.
Tweet