Skip to content

Commit

Permalink
New models
Browse files Browse the repository at this point in the history
  • Loading branch information
troyanskiy committed Mar 26, 2017
1 parent f7e0a99 commit 4f2319a
Show file tree
Hide file tree
Showing 14 changed files with 216 additions and 280 deletions.
12 changes: 12 additions & 0 deletions README.md
Expand Up @@ -190,6 +190,18 @@ export class PageComponent implements OnInit {
```
# Changes

## Version 2.0.0
Support Angular 4

#### Breaking
ResourceModel is simplified.

New model migration steps:


Please check bellow the example.


## Version 1.14.0 (Removed broken chance from ver 1.13.0)
Added resource method `initResultObject` which is used to create return object or items in returned array.<br>
The method should return object. If method `$setData` exists on the return object, then it will be called with
Expand Down
2 changes: 1 addition & 1 deletion index.ts
@@ -1,4 +1,4 @@
import { NgModule, ModuleWithProviders } from '@angular/core';
import { ModuleWithProviders, NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';
import { HttpModule } from '@angular/http';
import { ResourceProviders } from './src/ResourceProviders';
Expand Down
40 changes: 21 additions & 19 deletions package.json
Expand Up @@ -3,6 +3,7 @@
"version": "1.14.0",
"description": "Angular2 resource module with simple decorators",
"scripts": {
"clear": "rm ./*.d.ts && rm ./*.metadata.json && rm ./index.js && rm ./ng2-resource-rest.js && rm ./src/*.json && rm ./src/*.d.ts && rm ./src/*.js",
"ngc": "ngc",
"compile": "ngc && npm run build",
"build": "webpack && cp bundles/ng2-resource-rest.umd.js bundles/index.js"
Expand All @@ -29,28 +30,29 @@
},
"homepage": "https://github.com/troyanskiy/ng2-resource-rest#readme",
"peerDependencies": {
"@angular/core": "^2.0.0",
"@angular/common": "^2.0.0",
"@angular/http": "^2.0.0"
"@angular/core": ">=2.0.0",
"@angular/common": ">=2.0.0",
"@angular/http": ">=2.0.0"
},
"devDependencies": {
"@angular/common": "2.4.0",
"@angular/compiler": "2.4.0",
"@angular/compiler-cli": "2.4.0",
"@angular/core": "2.4.0",
"@angular/http": "2.4.0",
"@angular/platform-browser": "2.4.0",
"@angular/platform-server": "2.4.0",
"@types/node": "6.0.52",
"awesome-typescript-loader": "3.0.0-beta.17",
"codelyzer": "2.0.0-beta.3",
"rxjs": "5.0.1",
"@angular/common": "4.0.0",
"@angular/compiler": "4.0.0",
"@angular/compiler-cli": "4.0.0",
"@angular/core": "4.0.0",
"@angular/http": "4.0.0",
"@angular/platform-browser": "4.0.0",
"@angular/platform-server": "4.0.0",
"@types/node": "7.0.11",
"awesome-typescript-loader": "3.1.2",
"clean-webpack-plugin": "0.1.16",
"codelyzer": "3.0.0-beta.4",
"rxjs": "5.2.0",
"ts-helpers": "1.1.2",
"tslint": "4.0.2",
"tslint-loader": "3.3.0",
"typescript": "2.0.10",
"webpack": "2.1.0-beta.28",
"zone.js": "0.7.2"
"tslint": "4.5.1",
"tslint-loader": "3.4.3",
"typescript": "2.2.1",
"webpack": "2.3.2",
"zone.js": "0.8.5"
},
"dependencies": {}
}
3 changes: 2 additions & 1 deletion src/Interfaces.ts
@@ -1,6 +1,6 @@
import { Observable } from 'rxjs/Rx';
import { Request, RequestMethod } from '@angular/http';
import { Type } from '@angular/core/src/type';
import { Type } from '@angular/core';
import { ResourceModel } from './ResourceModel';
import { Resource } from './Resource';

Expand Down Expand Up @@ -72,4 +72,5 @@ export type ResourceResult<R extends {}> = R & {
$resolved?: boolean;
$observable?: Observable<R>;
$abortRequest?: () => void;
$resource?: Resource;
};
20 changes: 11 additions & 9 deletions src/Resource.ts
@@ -1,27 +1,20 @@
import { Http, Request } from '@angular/http';
import { Injector } from '@angular/core';
import { Type } from '@angular/core/src/type';
import { Observable } from 'rxjs/Rx';
import { ResourceGlobalConfig } from './ResourceGlobalConfig';
import { ResourceModel } from './ResourceModel';
import { ResourceParamsBase } from './Interfaces';
import { ResourceActionBase } from './Interfaces';
import { ResourceModel } from './ResourceModel';

export class Resource {

static model: Type<ResourceModel<Resource>>;

private _url: string = null;
private _path: string = null;
private _headers: any = null;
private _params: any = null;
private _data: any = null;

constructor(protected http: Http, protected injector: Injector) {
if ((<any>this.constructor).model) {
(<any>this.constructor).model.resourceInstance = this;
}
}
constructor(protected http: Http, protected injector: Injector) {}

/**
* Get main url of the resource
Expand Down Expand Up @@ -142,6 +135,15 @@ export class Resource {
}


createModel(): ResourceModel<any> {
let ret = this.initResultObject();
ret.$resource = this;
return ret;
}




protected _request(req: Request, methodOptions: ResourceActionBase = {}): Observable<any> {

let requestObservable = this.http.request(req);
Expand Down

0 comments on commit 4f2319a

Please sign in to comment.