Skip to content

Commit 97c7930

Browse files
committed
Merge branch 'release/3.0.0-beta7'
2 parents a5c255c + 1268926 commit 97c7930

17 files changed

+151
-75
lines changed

CHANGELOG.md

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,40 @@
1-
<a name="3.0.0-beta56></a>
1+
<a name="3.0.0-beta7></a>
2+
### 3.0.0-beta7 (2017-02-04)
3+
4+
* BREAKING CHANGE: `WpApiModule.initializeApp` is now `WpApiModule.forRoot`
5+
6+
Follow the following docs to migrate to the new way to bootstrap your module:
7+
8+
An exported function instead `WpApiLoaderFactory` is mandatory to be used with [AoT compilation](https://angular.io/docs/ts/latest/cookbook/aot-compiler.html) or [Ionic 2](http://ionic.io/).
9+
10+
11+
```js
12+
import { Http } from '@angular/http';
13+
import {
14+
WpApiModule
15+
WpApiLoader,
16+
WpApiStaticLoader
17+
} from 'wp-api-angular'
18+
19+
export function WpApiLoaderFactory(http: Http) {
20+
return new WpApiStaticLoader(http, 'http://YOUR_DOMAIN/wp-json/', /* namespace is optional, default: '/wp/v2' */);
21+
}
22+
23+
@NgModule({
24+
imports: [
25+
BrowserModule,
26+
WpApiModule.forRoot({
27+
provide: WpApiLoader,
28+
useFactory: (WpApiLoaderFactory),
29+
deps: [Http]
30+
})
31+
],
32+
bootstrap: [App]
33+
})
34+
export class AppModule { }
35+
```
36+
37+
<a name="3.0.0-beta6></a>
238
### 3.0.0-beta6 (2017-02-01)
339

440
export missing tokens to fix aot in ionic cli

README.md

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -30,22 +30,30 @@ UMD files are available `wp-api-angular.umd.js` and `wp-api-angular.umd.min.js`,
3030

3131
## Bootstrap
3232

33+
An exported function instead `WpApiLoaderFactory` is mandatory to be used with [AoT compilation](https://angular.io/docs/ts/latest/cookbook/aot-compiler.html) or [Ionic 2](http://ionic.io/).
34+
3335

3436
```js
35-
import { NgModule } from '@angular/core';
36-
import { BrowserModule } from '@angular/platform-browser';
37-
import { WpApiModule } from 'wp-api-angular'
38-
import { App } from './app';
37+
import { Http } from '@angular/http';
38+
import {
39+
WpApiModule,
40+
WpApiLoader,
41+
WpApiStaticLoader
42+
} from 'wp-api-angular'
43+
44+
export function WpApiLoaderFactory(http: Http) {
45+
return new WpApiStaticLoader(http, 'http://YOUR_DOMAIN/wp-json/', /* namespace is optional, default: '/wp/v2' */);
46+
}
3947

4048
@NgModule({
4149
imports: [
4250
BrowserModule,
43-
WpApiModule.initializeApp({
44-
baseUrl: "http://YOUR_DOMAIN/wp-json/",
45-
namespace: '/wp/v2' // (optional, default: '/wp/v2')
51+
WpApiModule.forRoot({
52+
provide: WpApiLoader,
53+
useFactory: (WpApiLoaderFactory),
54+
deps: [Http]
4655
})
4756
],
48-
declarations: [App],
4957
bootstrap: [App]
5058
})
5159
export class AppModule { }

demo/module.ts

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,29 @@
11
import { NgModule } from '@angular/core';
22
import { BrowserModule } from '@angular/platform-browser';
33
import 'rxjs/add/operator/toPromise';
4+
import { Http } from '@angular/http';
45
import {
5-
WpApiModule
6+
WpApiModule,
7+
WpApiLoader,
8+
WpApiStaticLoader
69
} from '../dist/wp-api-angular'
710
import { App } from './app';
811

912
let config = require('../config.json');
1013

1114
console.info('config', config);
1215

16+
export function WpApiLoaderFactory(http: Http) {
17+
return new WpApiStaticLoader(http, config.baseUrl);
18+
}
19+
1320
@NgModule({
1421
imports: [
1522
BrowserModule,
16-
WpApiModule.initializeApp({
17-
baseUrl: config.baseUrl
23+
WpApiModule.forRoot({
24+
provide: WpApiLoader,
25+
useFactory: (WpApiLoaderFactory),
26+
deps: [Http]
1827
})
1928
],
2029
declarations: [App],

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "wp-api-angular",
3-
"version": "3.0.0-beta6",
3+
"version": "3.0.0-beta7",
44
"description": "WordPress WP-API v2 client for Angular2",
55
"main": "wp-api-angular.js",
66
"typings": "wp-api-angular.d.ts",

src/Comments.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ import { RequestOptionsArgs } from '@angular/http/src/interfaces';
77
import { Response } from '@angular/http/src/static_response';
88

99
import { WpApiParent } from './Parent';
10-
import { WpApiConfig } from './tokens';
11-
import { WpApiAppConfig } from './wp-api-angular';
10+
11+
import { WpApiLoader } from './Loaders';
1212

1313
export interface IWpApiComments {
1414
getList(options?: RequestOptionsArgs): Observable<Response>;
@@ -21,10 +21,10 @@ export interface IWpApiComments {
2121
@Injectable()
2222
export class WpApiComments extends WpApiParent implements IWpApiComments {
2323
constructor(
24-
@Inject(WpApiConfig) public config: WpApiAppConfig,
24+
public wpApiLoader: WpApiLoader,
2525
public http: Http
2626
) {
27-
super(config, http);
27+
super(wpApiLoader, http);
2828
}
2929
getList(options = {}) {
3030
return this.httpGet(`/comments`, options)

src/Custom.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ import { RequestOptionsArgs } from '@angular/http/src/interfaces';
88
import { Response } from '@angular/http/src/static_response';
99

1010
import { WpApiParent } from './Parent';
11-
import { WpApiConfig } from './tokens';
12-
import { WpApiAppConfig } from './wp-api-angular';
11+
12+
import { WpApiLoader } from './Loaders';
1313

1414
export interface IWpApiCustom {
1515
getList(options?: RequestOptionsArgs): Observable<Response>;
@@ -21,11 +21,11 @@ export interface IWpApiCustom {
2121

2222
export class Custom extends WpApiParent implements IWpApiCustom {
2323
constructor(
24-
@Inject(WpApiConfig) public config: WpApiAppConfig,
24+
public wpApiLoader: WpApiLoader,
2525
public http: Http,
2626
public entityName: string
2727
) {
28-
super(config, http);
28+
super(wpApiLoader, http);
2929
}
3030
getList(options = {}) {
3131
return this.httpGet(`/${this.entityName}`, options)
@@ -48,16 +48,16 @@ export class Custom extends WpApiParent implements IWpApiCustom {
4848
@Injectable()
4949
export class WpApiCustom extends WpApiParent {
5050
constructor(
51-
@Inject(WpApiConfig) public config: WpApiAppConfig,
51+
public wpApiLoader: WpApiLoader,
5252
public http: Http
5353
) {
54-
super(config, http);
54+
super(wpApiLoader, http);
5555
}
5656

5757
getInstance(entityName = '') {
5858
if (typeof entityName !== 'string') {
5959
throw new Error(`getInstance needs an entity name`);
6060
}
61-
return new Custom(this.config, this.http, entityName);
61+
return new Custom(this.wpApiLoader, this.http, entityName);
6262
}
6363
}

src/Loaders.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import { Http, HttpModule } from '@angular/http';
2+
import { stripTrailingSlash } from './utils';
3+
4+
export abstract class WpApiLoader {
5+
abstract getWebServiceUrl(postfix: string): string;
6+
}
7+
8+
export class WpApiStaticLoader implements WpApiLoader {
9+
completeUrl: string;
10+
constructor(
11+
private http: Http,
12+
private baseUrl: string = 'http://changeYourDomainHere.com/wp-json',
13+
private namespace: string = '/wp/v2'
14+
) {
15+
this.completeUrl = `${stripTrailingSlash(this.baseUrl)}${this.namespace}`;
16+
}
17+
18+
public getWebServiceUrl(postfix: string): string {
19+
return `${this.completeUrl}${postfix}`
20+
}
21+
}

src/Media.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ import { RequestOptionsArgs } from '@angular/http/src/interfaces';
88
import { Response } from '@angular/http/src/static_response';
99

1010
import { WpApiParent } from './Parent';
11-
import { WpApiConfig } from './tokens';
12-
import { WpApiAppConfig } from './wp-api-angular';
11+
12+
import { WpApiLoader } from './Loaders';
1313

1414
export interface IWpApiMedia {
1515
getList(options?: RequestOptionsArgs): Observable<Response>;
@@ -22,10 +22,10 @@ export interface IWpApiMedia {
2222
@Injectable()
2323
export class WpApiMedia extends WpApiParent implements IWpApiMedia {
2424
constructor(
25-
@Inject(WpApiConfig) public config: WpApiAppConfig,
25+
public wpApiLoader: WpApiLoader,
2626
public http: Http
2727
) {
28-
super(config, http);
28+
super(wpApiLoader, http);
2929
}
3030
getList(options = {}) {
3131
return this.httpGet(`/media`, options)

src/Pages.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ import { RequestOptionsArgs } from '@angular/http/src/interfaces';
88
import { Response } from '@angular/http/src/static_response';
99

1010
import { WpApiParent } from './Parent';
11-
import { WpApiConfig } from './tokens';
12-
import { WpApiAppConfig } from './wp-api-angular';
11+
12+
import { WpApiLoader } from './Loaders';
1313

1414
export interface IWpApiPages {
1515
getList(options?: RequestOptionsArgs): Observable<Response>;
@@ -26,10 +26,10 @@ export interface IWpApiPages {
2626
@Injectable()
2727
export class WpApiPages extends WpApiParent implements IWpApiPages {
2828
constructor(
29-
@Inject(WpApiConfig) public config: WpApiAppConfig,
29+
public wpApiLoader: WpApiLoader,
3030
public http: Http
3131
) {
32-
super(config, http);
32+
super(wpApiLoader, http);
3333
}
3434

3535
getList(options = {}) {

src/Parent.ts

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@ import { Observable } from 'rxjs/Observable';
77
import { RequestOptionsArgs } from '@angular/http/src/interfaces';
88
import { Response } from '@angular/http/src/static_response';
99

10-
import { WpApiAppConfig } from './wp-api-angular';
10+
import { WpApiLoader } from './Loaders';
1111
import { stripTrailingSlash } from './utils';
12-
import { WpApiConfig } from './tokens';
12+
1313

1414
export interface IParent {
1515
httpGet(url: string, options?: RequestOptionsArgs): Observable<Response>;
@@ -23,29 +23,26 @@ export interface IParent {
2323
@Injectable()
2424
export class WpApiParent implements IParent {
2525
constructor(
26-
@Inject(WpApiConfig) public config: WpApiAppConfig,
26+
public wpApiLoader: WpApiLoader,
2727
public http: Http
2828
) { }
2929

30-
getFullUrl(postfix: string): string {
31-
return `${stripTrailingSlash(this.config.baseUrl)}${this.config.namespace || '/wp/v2'}${postfix}`;
32-
}
3330
httpGet(url: string, options = {}) {
34-
return this.http.get(this.getFullUrl(url), options);
31+
return this.http.get(this.wpApiLoader.getWebServiceUrl(url), options);
3532
}
3633
httpHead(url: string, options = {}) {
37-
return this.http.head(this.getFullUrl(url), options);
34+
return this.http.head(this.wpApiLoader.getWebServiceUrl(url), options);
3835
}
3936
httpDelete(url: string, options = {}) {
40-
return this.http.delete(this.getFullUrl(url), options);
37+
return this.http.delete(this.wpApiLoader.getWebServiceUrl(url), options);
4138
}
4239
httpPost(url: string, body = {}, options = {}) {
43-
return this.http.post(this.getFullUrl(url), body, options);
40+
return this.http.post(this.wpApiLoader.getWebServiceUrl(url), body, options);
4441
}
4542
httpPut(url: string, body = {}, options = {}) {
46-
return this.http.put(this.getFullUrl(url), body, options);
43+
return this.http.put(this.wpApiLoader.getWebServiceUrl(url), body, options);
4744
}
4845
httpPatch(url: string, body = {}, options = {}) {
49-
return this.http.patch(this.getFullUrl(url), body, options);
46+
return this.http.patch(this.wpApiLoader.getWebServiceUrl(url), body, options);
5047
}
5148
}

src/Posts.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ import { RequestOptionsArgs } from '@angular/http/src/interfaces';
88
import { Response } from '@angular/http/src/static_response';
99

1010
import { WpApiParent } from './Parent';
11-
import { WpApiConfig } from './tokens';
12-
import { WpApiAppConfig } from './wp-api-angular';
11+
12+
import { WpApiLoader } from './Loaders';
1313

1414
export interface IWpApiPosts {
1515
getList(options?: RequestOptionsArgs): Observable<Response>;
@@ -30,10 +30,10 @@ export interface IWpApiPosts {
3030
@Injectable()
3131
export class WpApiPosts extends WpApiParent implements IWpApiPosts {
3232
constructor(
33-
@Inject(WpApiConfig) public config: WpApiAppConfig,
33+
public wpApiLoader: WpApiLoader,
3434
public http: Http
3535
) {
36-
super(config, http);
36+
super(wpApiLoader, http);
3737
}
3838
getList(options = {}) {
3939
return this.httpGet(`/posts`, options)

src/Statuses.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ import { RequestOptionsArgs } from '@angular/http/src/interfaces';
88
import { Response } from '@angular/http/src/static_response';
99

1010
import { WpApiParent } from './Parent';
11-
import { WpApiConfig } from './tokens';
12-
import { WpApiAppConfig } from './wp-api-angular';
11+
12+
import { WpApiLoader } from './Loaders';
1313

1414
export interface IWpApiStatuses {
1515
getList(options?: RequestOptionsArgs): Observable<Response>;
@@ -19,10 +19,10 @@ export interface IWpApiStatuses {
1919
@Injectable()
2020
export class WpApiStatuses extends WpApiParent implements IWpApiStatuses {
2121
constructor(
22-
@Inject(WpApiConfig) public config: WpApiAppConfig,
22+
public wpApiLoader: WpApiLoader,
2323
public http: Http
2424
) {
25-
super(config, http);
25+
super(wpApiLoader, http);
2626
}
2727
getList(options = {}) {
2828
return this.httpGet(`/statuses`, options)

src/Taxonomies.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ import { RequestOptionsArgs } from '@angular/http/src/interfaces';
88
import { Response } from '@angular/http/src/static_response';
99

1010
import { WpApiParent } from './Parent';
11-
import { WpApiConfig } from './tokens';
12-
import { WpApiAppConfig } from './wp-api-angular';
11+
12+
import { WpApiLoader } from './Loaders';
1313

1414
export interface IWpApiTaxonomies {
1515
getList(options?: RequestOptionsArgs): Observable<Response>;
@@ -19,10 +19,10 @@ export interface IWpApiTaxonomies {
1919
@Injectable()
2020
export class WpApiTaxonomies extends WpApiParent implements IWpApiTaxonomies {
2121
constructor(
22-
@Inject(WpApiConfig) public config: WpApiAppConfig,
22+
public wpApiLoader: WpApiLoader,
2323
public http: Http
2424
) {
25-
super(config, http);
25+
super(wpApiLoader, http);
2626
}
2727
getList(options = {}) {
2828
return this.httpGet(`/taxonomies`, options)

0 commit comments

Comments
 (0)