Skip to content

Commit

Permalink
Merge branch 'release/3.0.0-alpha8'
Browse files Browse the repository at this point in the history
  • Loading branch information
shprink committed Oct 30, 2016
2 parents 148ce4d + c7259f9 commit 8754f8c
Show file tree
Hide file tree
Showing 9 changed files with 2,473 additions and 73 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
<a name="3.0.0-alpha8"></a>
### 3.0.0-alpha8 (2016-10-30)

Upgrade to Angular 2.0.0 / NgModules

<a name="3.0.0-alpha7"></a>
### 3.0.0-alpha7 (2016-07-30)

Making sure it is usable via TypeScript as well (export d.ts files).


<a name="3.0.0-alpha2"></a>
### 3.0.0-alpha2 (2016-07-24)

Expand Down
34 changes: 18 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Angular2 services to consume [WP-API v2](http://v2.wp-api.org/)

[Live Demo](https://plnkr.co/edit/hqE4bvbM6HXql5Insjx8?p=preview)

If you want to use AngularJS v1, here is the latest version: [v2.0.0-rc3](https://github.com/shprink/wp-api-angular/tree/v2.0.0-rc3)
If you want to use AngularJS v1, here is the latest version: [v2.0.0-rc3](https://www.npmjs.com/package/wp-api-angularjs). `npm i wp-api-angularjs@v2.0.0-rc3`

## Installation

Expand All @@ -27,21 +27,23 @@ UMD files are available `wp-api-angular.umd.js` and `wp-api-angular.umd.min.js`,


```js
import {
WPAPI_PROVIDERS,
defaultWpApi
} from 'wp-api-angular';

import {App} from './app';

bootstrap(App, [
WPAPI_PROVIDERS,
defaultWpApi({
baseUrl: "http://YOUR_DOMAIN/wp-json/",
namespace: '/wp/v2' // (optional, default: '/wp/v2')
})
]);

import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { WpApiModule } from 'wp-api-angular'
import { App } from './app';

@NgModule({
imports: [
BrowserModule,
WpApiModule.initializeApp({
baseUrl: "http://YOUR_DOMAIN/wp-json/",
namespace: '/wp/v2' // (optional, default: '/wp/v2')
})
],
declarations: [App],
bootstrap: [App]
})
export class AppModule { }
```

## API
Expand Down
6 changes: 3 additions & 3 deletions demo/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,9 @@ export class App {
service[method].apply(service, parameters).toPromise()
.then(response => response.json())
.then(body => {
console.groupCollapsed(serviceName, method, JSON.stringify(parameters));
console.log(body);
console.groupEnd()
// console.groupCollapsed(serviceName, method, JSON.stringify(parameters));
// console.log(body);
// console.groupEnd()
this.requests.push({ serviceName: serviceName.slice(5), method, success: true })
})
.catch(error => {
Expand Down
19 changes: 3 additions & 16 deletions demo/index.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,4 @@
import {provide} from '@angular/core';
import { bootstrap } from '@angular/platform-browser-dynamic';
import 'rxjs/add/operator/toPromise';
import {
WPAPI_PROVIDERS,
defaultWpApi
} from '../dist/wp-api-angular'
let config = require('../config.json');
import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';
import { AppModule } from './module';

import {App} from './app';

bootstrap(App, [
WPAPI_PROVIDERS,
defaultWpApi({
baseUrl: config.baseUrl
})
]);
platformBrowserDynamic().bootstrapModule(AppModule);
23 changes: 23 additions & 0 deletions demo/module.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import 'rxjs/add/operator/toPromise';
import {
WpApiModule
} from '../dist/wp-api-angular'
import { App } from './app';

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

console.info('config', config);

@NgModule({
imports: [
BrowserModule,
WpApiModule.initializeApp({
baseUrl: config.baseUrl
})
],
declarations: [App],
bootstrap: [App]
})
export class AppModule { }
23 changes: 10 additions & 13 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "wp-api-angular",
"version": "3.0.0-alpha7",
"version": "3.0.0-alpha8",
"description": "WordPress WP-API v2 client for Angular2",
"main": "wp-api-angular.js",
"typings": "wp-api-angular.d.ts",
Expand Down Expand Up @@ -34,31 +34,28 @@
"url": "https://github.com/shprink/wp-api-angular/issues"
},
"homepage": "https://github.com/shprink/wp-api-angular",
"dependencies": {
"@angular/common": "^2.0.0",
"@angular/compiler": "^2.0.0",
"@angular/core": "^2.0.0",
"@angular/http": "^2.1.2",
"@angular/platform-browser": "^2.0.0",
"@angular/platform-browser-dynamic": "^2.0.0",
"rxjs": "5.0.0-beta.12"
},
"devDependencies": {
"@angular/common": "^2.0.0-rc.4",
"@angular/compiler": "^2.0.0-rc.4",
"@angular/core": "^2.0.0-rc.4",
"@angular/http": "^2.0.0-rc.4",
"@angular/platform-browser": "^2.0.0-rc.4",
"@angular/platform-browser-dynamic": "^2.0.0-rc.4",
"babel-core": "^6.10.4",
"babel-loader": "^6.2.4",
"core-js": "^2.4.0",
"html-webpack-plugin": "~2.22.0",
"json-loader": "^0.5.2",
"path": "^0.4.9",
"reflect-metadata": "^0.1.3",
"rxjs": "5.0.0-beta.6",
"ts-loader": "0.8.1",
"typescript": "~1.8.10",
"util": "^0.10.3",
"webpack": "~1.13.1",
"webpack-dev-server": "~1.14.1",
"zone.js": "^0.6.12"
},
"peerDependencies": {
"@angular/core": "2.0.0-rc.2 || 2.0.0-rc.3 || 2.0.0-rc.4 || 2.0.0-rc.5 || 2.0.0-rc.6 || 2.0.0-rc.7 || 2.0.0-rc.8 || 2.0.0-rc.9",
"@angular/http": "2.0.0-rc.2 || 2.0.0-rc.3 || 2.0.0-rc.4 || 2.0.0-rc.5 || 2.0.0-rc.6 || 2.0.0-rc.7 || 2.0.0-rc.8 || 2.0.0-rc.9",
"rxjs": "5.0.0-beta.6"
}
}
55 changes: 31 additions & 24 deletions src/wp-api-angular.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import {
provide,
Provider
Provider,
NgModule,
ModuleWithProviders
} from '@angular/core';
import 'rxjs';
import { Http, HTTP_PROVIDERS } from '@angular/http';
import { Http, HttpModule } from '@angular/http';

import { stripTrailingSlash } from './utils';
import { WpApiApp, WpApiConfig } from './tokens';
Expand Down Expand Up @@ -35,28 +36,34 @@ export interface WpApiAppConfig {
namespace?: string;
}

export const defaultWpApi = (config: WpApiAppConfig): Provider => {
// remove a trailing slash
config.baseUrl = stripTrailingSlash(config.baseUrl);
config.namespace = config.namespace || '/wp/v2';
return provide(WpApiConfig, {
useValue: config
});
};
@NgModule({
imports: [
HttpModule
]
})
export class WpApiModule {
static initializeApp(config: WpApiAppConfig): ModuleWithProviders {
config.baseUrl = stripTrailingSlash(config.baseUrl);
config.namespace = config.namespace || '/wp/v2';

export const WPAPI_PROVIDERS: any[] = [
HTTP_PROVIDERS,
createProvider(WpApiPosts),
createProvider(WpApiPages),
createProvider(WpApiComments),
createProvider(WpApiTypes),
createProvider(WpApiMedia),
createProvider(WpApiUsers),
createProvider(WpApiTaxonomies),
createProvider(WpApiStatuses),
createProvider(WpApiTerms),
createProvider(WpApiCustom)
];
return {
ngModule: WpApiModule,
providers: [
{ provide: WpApiConfig, useValue: config },
createProvider(WpApiPosts),
createProvider(WpApiPages),
createProvider(WpApiComments),
createProvider(WpApiTypes),
createProvider(WpApiMedia),
createProvider(WpApiUsers),
createProvider(WpApiTaxonomies),
createProvider(WpApiStatuses),
createProvider(WpApiTerms),
createProvider(WpApiCustom)
]
};
}
}

function createProvider(service) {
return {
Expand Down
2 changes: 1 addition & 1 deletion webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ module.exports = {
entry: {
aPolyfills: [
'core-js',
'reflect-metadata',
'reflect-metadata/Reflect.js',
'zone.js'
],
bVendors: [
Expand Down
Loading

0 comments on commit 8754f8c

Please sign in to comment.