Skip to content

Commit

Permalink
Merge pull request #46 from MurhafSousli/dev
Browse files Browse the repository at this point in the history
Update for beta.6
  • Loading branch information
MurhafSousli authored Oct 7, 2018
2 parents 5bbd7b2 + 1cbb590 commit 4269e5d
Show file tree
Hide file tree
Showing 16 changed files with 1,297 additions and 159 deletions.
2 changes: 1 addition & 1 deletion projects/core/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@ngx-wordpress/core",
"version": "5.0.0-beta.5",
"version": "5.0.0-beta.6",
"description": "The best WordPress module for Angular",
"repository": {
"type": "git",
Expand Down
2 changes: 1 addition & 1 deletion projects/core/src/lib/auth/wp-auth-ref.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export class WpAuthRef {
/**
* Stream that emits WpAuth state
*/
private _state = new BehaviorSubject<WpAuthState>(defaultAuthState);
private _state = new BehaviorSubject<WpAuthState>({...defaultAuthState});
state: Observable<any> = this._state.asObservable();

/**
Expand Down
10 changes: 5 additions & 5 deletions projects/core/src/lib/collection/wp-collection-ref.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { BehaviorSubject, Observable, Subject, of, forkJoin } from 'rxjs';
import { catchError, distinctUntilChanged, filter, map, switchMap, take } from 'rxjs/operators';
import { catchError, distinctUntilChanged, filter, first, map, switchMap } from 'rxjs/operators';
import { WpCollectionState, WpPagination, WpQuery } from './wp-collection.interface';
import { WpCollectionService } from './wp-collection.service';
import { WpConfig } from '../interfaces';
Expand Down Expand Up @@ -37,7 +37,7 @@ export class WpCollectionRef {
/**
* Stream that emits WpCollection state
*/
private _state = new BehaviorSubject<WpCollectionState>(defaultCollectionState);
private _state = new BehaviorSubject<WpCollectionState>({ ...defaultCollectionState});
state = this._state.asObservable();

/**
Expand Down Expand Up @@ -104,7 +104,7 @@ export class WpCollectionRef {
*/
more(): Observable<WpCollectionState> {
return this.state.pipe(
take(1),
first(),
filter((state: WpCollectionState) => state.pagination.hasMore),
switchMap((state: WpCollectionState) => {
/** increment currentPage then set page argument */
Expand All @@ -120,7 +120,7 @@ export class WpCollectionRef {
*/
next(): Observable<WpCollectionState> {
return this.state.pipe(
take(1),
first(),
filter((state: WpCollectionState) => state.pagination.hasMore),
switchMap((state: WpCollectionState) => {
/** increment currentPage then set page argument */
Expand All @@ -136,7 +136,7 @@ export class WpCollectionRef {
*/
prev(): Observable<WpCollectionState> {
return this.state.pipe(
take(1),
first(),
filter((state: WpCollectionState) => state.pagination.hasPrev),
switchMap((state: WpCollectionState) => {
/** decrement currentPage then set page argument */
Expand Down
4 changes: 2 additions & 2 deletions projects/core/src/lib/collection/wp-collection.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { HttpClient, HttpResponse } from '@angular/common/http';
import { Observable } from 'rxjs';
import { map } from 'rxjs/operators';
import { serializeQuery } from '../utilities';
import { WpCollectionState } from './wp-collection.interface';
import { WpCollectionState, WpQuery } from './wp-collection.interface';

@Injectable({
providedIn: 'root'
Expand All @@ -16,7 +16,7 @@ export class WpCollectionService {
/**
* Fetch data from wp api
*/
get(endpoint, query): Observable<WpCollectionState> {
get(endpoint: string, query: WpQuery): Observable<WpCollectionState> {
const url = endpoint + '?' + serializeQuery(query);
return this.http.get(url, {observe: 'response'}).pipe(
map((res: HttpResponse<any>) => this._onPaginate(res, query.page))
Expand Down
7 changes: 3 additions & 4 deletions projects/core/src/lib/decorators/wp-model.decorator.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,19 @@
import { WordPress } from '../wordpress.service';

export function WpModel(endpoint?: string) {

return function (target: any, name: string) {
const selectorFnName = '__' + name + '__selector';

const createSelect = x => {
const createSelect = (res: { endpoint: string }) => {
const wp = WordPress.wp;
if (!wp) {
throw new Error('ModelFactory not connected to WordPress!');
}
return wp.model(x);
return wp.model(res.endpoint);
};

const createSelector = () => {
return endpoint;
return {endpoint};
};

if (delete target[name]) {
Expand Down
4 changes: 3 additions & 1 deletion projects/core/src/lib/interfaces/wp-user.interface.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
export interface WpUser {
id?: string;
id?: string | number;
name?: string;
url?: string;
link?: string;
description?: string;
slug?: string;
avatar_urls?: {
24?: string,
48?: string,
96?: string
};
meta?: any[];
_links?: any;
}
2 changes: 1 addition & 1 deletion projects/core/src/lib/model/wp-model-ref.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export class WpModelRef {
/**
* Stream that emits WpModel state
*/
private _state = new BehaviorSubject<WpModelState>(defaultModelState);
private _state = new BehaviorSubject<WpModelState>({...defaultModelState});
state = this._state.asObservable();

/**
Expand Down
4 changes: 2 additions & 2 deletions projects/core/src/lib/wordpress.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,9 @@ export class WordPress {
constructor(private http: HttpClient,
private modelHttp: WpModelService,
private collectionHttp: WpCollectionService,
@Inject(PLATFORM_ID) private platform: Object,
private jwt: JwtService,
@Inject(WP_CONFIG) config: WpConfig,
private jwt: JwtService
@Inject(PLATFORM_ID) private platform: Object
) {
// Make WordPress available for decorators
WordPress.wp = this;
Expand Down
11 changes: 6 additions & 5 deletions projects/mock/package.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
{
"name": "mock",
"version": "0.0.1",
"name": "@ngx-wordpress/mock",
"version": "5.0.0-beta.6",
"peerDependencies": {
"@angular/common": "^6.0.0-rc.0 || ^6.0.0",
"@angular/core": "^6.0.0-rc.0 || ^6.0.0"
"@angular/common": "^6.0.0",
"@angular/core": "^6.0.0",
"rxjs": "^6.0.0"
}
}
}
3 changes: 3 additions & 0 deletions projects/mock/src/lib/auth.data.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export const validateTokenData = {

};
Loading

0 comments on commit 4269e5d

Please sign in to comment.