├── app
├── bootstrap.js
├── bootstrap.ts
├── components
│ ├── app.js
│ ├── app.ts
│ ├── artist
│ │ ├── artist.js
│ │ └── artist.ts
│ └── search
│ │ ├── search.js
│ │ └── search.ts
├── services
│ ├── spotify.js
│ └── spotify.ts
└── utils
│ ├── fetch.js
│ └── fetch.ts
├── index.html
└── typings
├── _custom.d.ts
├── angular2
├── angular2.d.ts
└── router.d.ts
├── es6-promise
└── es6-promise.d.ts
└── rx
└── rx.d.ts
/app/bootstrap.js:
--------------------------------------------------------------------------------
1 | ///
2 | var angular2_1 = require('angular2/angular2');
3 | var router_1 = require('angular2/router');
4 | var spotify_1 = require('./services/spotify');
5 | var app_1 = require('./components/app');
6 | var universalInjectables = [
7 | router_1.routerInjectables,
8 | spotify_1.Spotify,
9 | angular2_1.bind(router_1.LocationStrategy).toClass(router_1.HashLocationStrategy)
10 | ];
11 | angular2_1.bootstrap(app_1.App, [universalInjectables]);
12 |
--------------------------------------------------------------------------------
/app/bootstrap.ts:
--------------------------------------------------------------------------------
1 | ///
2 |
3 | import { bootstrap, bind } from 'angular2/angular2';
4 |
5 | import { routerInjectables, LocationStrategy, HashLocationStrategy } from 'angular2/router';
6 |
7 | import { Spotify } from './services/spotify';
8 | import { App } from './components/app';
9 |
10 |
11 | var universalInjectables = [
12 | routerInjectables,
13 | Spotify,
14 | bind(LocationStrategy).toClass(HashLocationStrategy)
15 | ];
16 |
17 | bootstrap(App, [universalInjectables]);
--------------------------------------------------------------------------------
/app/components/app.js:
--------------------------------------------------------------------------------
1 | ///
2 | var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3 | if (typeof Reflect === "object" && typeof Reflect.decorate === "function") return Reflect.decorate(decorators, target, key, desc);
4 | switch (arguments.length) {
5 | case 2: return decorators.reduceRight(function(o, d) { return (d && d(o)) || o; }, target);
6 | case 3: return decorators.reduceRight(function(o, d) { return (d && d(target, key)), void 0; }, void 0);
7 | case 4: return decorators.reduceRight(function(o, d) { return (d && d(target, key, o)) || o; }, desc);
8 | }
9 | };
10 | var __metadata = (this && this.__metadata) || function (k, v) {
11 | if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
12 | };
13 | var angular2_1 = require('angular2/angular2');
14 | var router_1 = require('angular2/router');
15 | var search_1 = require('../components/search/search');
16 | var artist_1 = require('../components/artist/artist');
17 | var App = (function () {
18 | function App() {
19 | this.title = 'App title';
20 | }
21 | App = __decorate([
22 | angular2_1.Component({
23 | selector: 'app'
24 | }),
25 | angular2_1.View({
26 | directives: [router_1.RouterLink, router_1.RouterOutlet],
27 | template: "\n\t\t\n\t\t\t\n\t\t\n\t\t\n\t\t\n\t\t\t{{title}}
\n\t\t\t\n\t\t\n\t"
28 | }),
29 | router_1.RouteConfig([
30 | { path: '/', redirectTo: '/search' },
31 | { path: '/search', as: 'search', component: search_1.Search },
32 | { path: '/artist/:id', as: 'artist', component: artist_1.Artist }
33 | ]),
34 | __metadata('design:paramtypes', [])
35 | ], App);
36 | return App;
37 | })();
38 | exports.App = App;
39 |
--------------------------------------------------------------------------------
/app/components/app.ts:
--------------------------------------------------------------------------------
1 | ///
2 |
3 | import { Component, View } from 'angular2/angular2';
4 | import { RouteConfig, RouterLink, RouterOutlet } from 'angular2/router';
5 |
6 | import { Search } from '../components/search/search';
7 | import { Artist } from '../components/artist/artist';
8 |
9 | @Component({
10 | selector: 'app'
11 | })
12 |
13 | @View({
14 | directives: [RouterLink, RouterOutlet],
15 | template: `
16 |
25 |
26 |
27 | {{title}}
28 |
29 |
30 | `
31 | })
32 |
33 | @RouteConfig([
34 | { path: '/', redirectTo: '/search' },
35 | { path: '/search', as: 'search', component: Search },
36 | { path: '/artist/:id', as: 'artist', component: Artist }
37 | ])
38 |
39 | export class App {
40 | title: string;
41 | constructor() {
42 | this.title = 'App title';
43 | }
44 | }
--------------------------------------------------------------------------------
/app/components/artist/artist.js:
--------------------------------------------------------------------------------
1 | ///
2 | var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3 | if (typeof Reflect === "object" && typeof Reflect.decorate === "function") return Reflect.decorate(decorators, target, key, desc);
4 | switch (arguments.length) {
5 | case 2: return decorators.reduceRight(function(o, d) { return (d && d(o)) || o; }, target);
6 | case 3: return decorators.reduceRight(function(o, d) { return (d && d(target, key)), void 0; }, void 0);
7 | case 4: return decorators.reduceRight(function(o, d) { return (d && d(target, key, o)) || o; }, desc);
8 | }
9 | };
10 | var __metadata = (this && this.__metadata) || function (k, v) {
11 | if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
12 | };
13 | var angular2_1 = require('angular2/angular2');
14 | var router_1 = require('angular2/router');
15 | var spotify_1 = require('../../services/spotify');
16 | var fetch_1 = require('../../utils/fetch');
17 | var Artist = (function () {
18 | function Artist(service, routeParam) {
19 | this.service = service;
20 | this.routeParam = routeParam;
21 | this.getArtist();
22 | }
23 | Artist.prototype.getArtist = function () {
24 | var _this = this;
25 | this.service.getArtistById(this.routeParam.params.id)
26 | .then(fetch_1.status)
27 | .then(fetch_1.json)
28 | .then(function (response) {
29 | _this.artist = response;
30 | _this.image = response.images[0].url;
31 | });
32 | };
33 | Artist = __decorate([
34 | angular2_1.Component({
35 | selector: 'artist',
36 | viewInjector: [spotify_1.Spotify]
37 | }),
38 | angular2_1.View({
39 | directives: [angular2_1.NgIf],
40 | template: "\n\t\t\n\t\t\t{{artist.name}}
\n\t\t\t
\n\t\t\n\t"
41 | }),
42 | __metadata('design:paramtypes', [spotify_1.Spotify, router_1.RouteParams])
43 | ], Artist);
44 | return Artist;
45 | })();
46 | exports.Artist = Artist;
47 |
--------------------------------------------------------------------------------
/app/components/artist/artist.ts:
--------------------------------------------------------------------------------
1 | ///
2 |
3 | import { Component, View, NgIf } from 'angular2/angular2';
4 | import { RouterLink, RouteParams } from 'angular2/router';
5 | import { Spotify } from '../../services/spotify';
6 | import { status, json } from '../../utils/fetch'
7 |
8 | @Component({
9 | selector: 'artist',
10 | viewInjector: [Spotify]
11 | })
12 | @View({
13 | directives: [NgIf],
14 | template: `
15 |
16 | {{artist.name}}
17 |
18 |
19 | `
20 | })
21 |
22 | export class Artist {
23 | artist: Object;
24 | service: Spotify;
25 | routeParam: RouteParams;
26 | image: string;
27 | constructor(service: Spotify, routeParam: RouteParams) {
28 | this.service = service;
29 | this.routeParam = routeParam;
30 | this.getArtist();
31 | }
32 | getArtist() {
33 | this.service.getArtistById(this.routeParam.params.id)
34 | .then(status)
35 | .then(json)
36 | .then((response) => {
37 | this.artist = response;
38 | this.image = response.images[0].url;
39 | })
40 | }
41 | }
--------------------------------------------------------------------------------
/app/components/search/search.js:
--------------------------------------------------------------------------------
1 | ///
2 | var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3 | if (typeof Reflect === "object" && typeof Reflect.decorate === "function") return Reflect.decorate(decorators, target, key, desc);
4 | switch (arguments.length) {
5 | case 2: return decorators.reduceRight(function(o, d) { return (d && d(o)) || o; }, target);
6 | case 3: return decorators.reduceRight(function(o, d) { return (d && d(target, key)), void 0; }, void 0);
7 | case 4: return decorators.reduceRight(function(o, d) { return (d && d(target, key, o)) || o; }, desc);
8 | }
9 | };
10 | var __metadata = (this && this.__metadata) || function (k, v) {
11 | if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
12 | };
13 | var angular2_1 = require('angular2/angular2');
14 | var router_1 = require('angular2/router');
15 | var spotify_1 = require('../../services/spotify');
16 | var fetch_1 = require('../../utils/fetch');
17 | var Search = (function () {
18 | function Search(service) {
19 | this.service = service;
20 | }
21 | Search.prototype.searchArtist = function ($event, value) {
22 | var _this = this;
23 | if (!value) {
24 | return;
25 | }
26 | if (this.timeoutId)
27 | clearTimeout(this.timeoutId);
28 | this.timeoutId = setTimeout(function () {
29 | _this.service.searchArtist(value)
30 | .then(fetch_1.status)
31 | .then(fetch_1.json)
32 | .then(function (response) {
33 | _this.setResults(response.artists.items);
34 | });
35 | }, 250);
36 | };
37 | Search.prototype.setResults = function (artists) {
38 | this.artists = artists;
39 | };
40 | Search = __decorate([
41 | angular2_1.Component({
42 | selector: 'search',
43 | viewInjector: [spotify_1.Spotify]
44 | }),
45 | angular2_1.View({
46 | directives: [angular2_1.NgFor, router_1.RouterLink],
47 | template: "\n\t\t\n\t\t\n\t\t
Results
\n\t\t\n\t"
48 | }),
49 | __metadata('design:paramtypes', [spotify_1.Spotify])
50 | ], Search);
51 | return Search;
52 | })();
53 | exports.Search = Search;
54 |
--------------------------------------------------------------------------------
/app/components/search/search.ts:
--------------------------------------------------------------------------------
1 | ///
2 |
3 | import { Component, View, NgFor, Inject } from 'angular2/angular2';
4 | import { RouterLink, RouteParams } from 'angular2/router';
5 | import { Spotify } from '../../services/spotify';
6 | import { status, json } from '../../utils/fetch'
7 |
8 | @Component({
9 | selector: 'search',
10 | viewInjector: [Spotify]
11 | })
12 | @View({
13 | directives: [NgFor, RouterLink],
14 | template: `
15 |
16 |
17 | Results
18 |
24 | `
25 | })
26 |
27 | export class Search {
28 | timeoutId: number;
29 | artists: Object;
30 | service: Spotify;
31 | constructor(service: Spotify) {
32 | this.service = service;
33 | }
34 | searchArtist($event, value) {
35 | if (!value) {
36 | return;
37 | }
38 | if (this.timeoutId) clearTimeout(this.timeoutId);
39 | this.timeoutId = setTimeout(() => {
40 | this.service.searchArtist(value)
41 | .then(status)
42 | .then(json)
43 | .then((response) => {
44 | this.setResults(response.artists.items);
45 | })
46 | }, 250);
47 | }
48 | setResults(artists: Array