Skip to content

Commit 1f930bd

Browse files
Agnostic framework FE-272 (#326)
1 parent 9abbf24 commit 1f930bd

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+2233
-1799
lines changed

CHANGELOG.md

+12
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,24 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
66

77
## [Unreleased]
88

9+
## [3.0.0] - 2021-08-17
10+
11+
### Added
12+
13+
- Compatibility with other frameworks in addition to angular was added to the library. The behavior of the http.service.ts file was changed, it stopped using http client by axios to give compatibility with other libraries. It changed the way the library is initialized, a bootstrap was created that is found in the jsonapi-bootstrap file ([#326](https://github.com/reyesoft/ngx-jsonapi/pull/326))
14+
915
## [2.3.0] - 2021-05-19
1016

1117
### Changed
1218

1319
- Angular version upgraded to 10, and vulnerabilities updated. ([#306](https://github.com/reyesoft/ngx-jsonapi/pull/306))
1420

21+
## [2.2.3] - 2021-06-24
22+
23+
### Fixed
24+
25+
- Fix trackBy params of document-collection.ts. ([#299](https://github.com/reyesoft/ngx-jsonapi/pull/299))
26+
1527
## [2.2.2] - 2021-05-19
1628

1729
### Fixed

README.md

+56-28
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ Data is obtained from [Json Api Playground](https://jsonapiplayground.reyesoft.c
3434
## Migration
3535

3636
- [Migration v1 to v2 update guide](https://github.com/reyesoft/ngx-jsonapi/blob/v2.0/docs/migration.md)
37+
- [Migration v2 to v3 Angular update guide](https://github.com/reyesoft/ngx-jsonapi/blob/v2.0/docs/migration-v2-to-v3.md)
3738

3839
## Usage
3940

@@ -52,51 +53,75 @@ yarn add [email protected] --save
5253

5354
1. Add Jsonapi dependency.
5455
2. Configure your url and other paramemeters.
55-
3. Inject JsonapiCore somewhere before you extend any class from `Jsonapi.Resource`.
56+
57+
- Angular
5658

5759
```typescript
5860
/* .. */
5961
import { NgxJsonapiModule } from 'ngx-jsonapi';
6062

61-
@NgModule({
62-
imports: [
63-
NgxJsonapiModule.forRoot({
64-
url: '//jsonapiplayground.reyesoft.com/v2/'
65-
})
66-
]
67-
})
68-
export class AppModule {}
63+
@NgModule()
64+
export class AppModule {
65+
public constructor() {
66+
JsonapiBootstrap({
67+
user_config: { url: '//jsonapiplayground.reyesoft.com/v2/' }
68+
});
69+
}
70+
}
71+
```
72+
73+
- React
74+
75+
```typescript
76+
import { NgxJsonapiModule } from 'ngx-jsonapi';
77+
78+
const App = () => {
79+
JsonapiBootstrap({
80+
user_config: { url: '//jsonapiplayground.reyesoft.com/v2/' }
81+
});
82+
83+
return <div>Hello world</div>;
84+
};
6985
```
7086

7187
### Enable Local Cache
7288

7389
Library cache anything memory. With Local Store, also store all on IndexDb on browser. Faster apps when we reuse a lot of data.
7490

91+
- Angular
92+
7593
```typescript
7694
/* .. */
7795
import { NgxJsonapiModule } from 'ngx-jsonapi';
78-
import { JSONAPI_RIPPER_SERVICE, JSONAPI_STORE_SERVICE } from './core';
7996
import { StoreService } from 'ngx-jsonapi/sources/store.service';
8097
import { JsonRipper } from 'ngx-jsonapi/services/json-ripper';
8198

82-
@NgModule({
83-
imports: [
84-
NgxJsonapiModule.forRoot({
85-
url: '//jsonapiplayground.reyesoft.com/v2/'
86-
})
87-
],
88-
providers: [
89-
{
90-
provide: JSONAPI_RIPPER_SERVICE,
91-
useClass: JsonRipperFake
92-
},
93-
{
94-
provide: JSONAPI_STORE_SERVICE,
95-
useClass: StoreFakeService
96-
}
97-
]
98-
})
99-
export class AppModule {}
99+
@NgModule()
100+
export class AppModule {
101+
public constructor() {
102+
JsonapiBootstrap({
103+
user_config: { url: '//jsonapiplayground.reyesoft.com/v2/' },
104+
jsonapiStore: new StoreFakeService(),
105+
jsonRipper: new JsonRipperFake()
106+
});
107+
}
108+
}
109+
```
110+
111+
- React
112+
113+
```typescript
114+
import { NgxJsonapiModule } from 'ngx-jsonapi';
115+
116+
const App = () => {
117+
JsonapiBootstrap({
118+
user_config: { url: '//jsonapiplayground.reyesoft.com/v2/' },
119+
jsonapiStore: new StoreFakeService(),
120+
jsonRipper: new JsonRipperFake()
121+
});
122+
123+
return <div>Hello world</div>;
124+
};
100125
```
101126

102127
## Examples
@@ -153,6 +178,9 @@ export class AuthorsComponent {
153178
authorsService
154179
.all({
155180
// include: ['books', 'photos'],
181+
// fields: {
182+
// authors: ['name']
183+
// }
156184
})
157185
.subscribe(authors => (this.authors = authors));
158186
}

demo/app/app.component.ts

+5-7
Original file line numberDiff line numberDiff line change
@@ -9,19 +9,17 @@ import { JsonapiCore } from 'ngx-jsonapi';
99
export class AppComponent /* implements OnInit */ {
1010
public loading = '';
1111

12-
public constructor(
13-
private jsonapiCore: JsonapiCore
14-
) {
15-
jsonapiCore.loadingsStart = (): void => {
12+
public constructor() {
13+
JsonapiCore.getInstance().loadingsStart = (): void => {
1614
this.loading = 'LOADING...';
1715
};
18-
jsonapiCore.loadingsDone = (): void => {
16+
JsonapiCore.getInstance().loadingsDone = (): void => {
1917
this.loading = '';
2018
};
21-
jsonapiCore.loadingsOffline = (error): void => {
19+
JsonapiCore.getInstance().loadingsOffline = (error): void => {
2220
this.loading = 'No connection!!!';
2321
};
24-
jsonapiCore.loadingsError = (error): void => {
22+
JsonapiCore.getInstance().loadingsError = (error): void => {
2523
this.loading = 'No connection 2!!!';
2624
};
2725
}

demo/app/app.module.ts

+7-16
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,14 @@ import { BrowserModule } from '@angular/platform-browser';
33
import { RouterModule, Routes } from '@angular/router';
44
import { HttpClientModule } from '@angular/common/http';
55
import { environment } from '../environments/environment';
6-
import { NgxJsonapiModule, JSONAPI_RIPPER_SERVICE, JSONAPI_STORE_SERVICE } from 'ngx-jsonapi';
76

87
import { AppComponent } from './app.component';
98
import { AuthorsService } from './authors/authors.service';
109
import { BooksService } from './books/books.service';
1110
import { PhotosService } from './photos/photos.service';
1211
import { SharedModule } from './shared/shared.module';
1312

14-
import { StoreService } from 'ngx-jsonapi/sources/store.service';
15-
import { JsonRipper } from 'ngx-jsonapi/services/json-ripper';
13+
import { JsonapiBootstrap } from 'ngx-jsonapi';
1614
import { AuthorsModule } from './authors/authors.module';
1715
import { BooksModule } from './books/books.module';
1816

@@ -34,14 +32,6 @@ const appRoutes: Routes = [
3432

3533
@NgModule({
3634
providers: [
37-
{
38-
provide: JSONAPI_RIPPER_SERVICE,
39-
useClass: JsonRipper
40-
},
41-
{
42-
provide: JSONAPI_STORE_SERVICE,
43-
useClass: StoreService
44-
},
4535
AuthorsService,
4636
BooksService,
4737
PhotosService
@@ -50,12 +40,13 @@ const appRoutes: Routes = [
5040
BrowserModule,
5141
HttpClientModule,
5242
SharedModule,
53-
RouterModule.forRoot(appRoutes, { useHash: true }),
54-
NgxJsonapiModule.forRoot({
55-
url: environment.jsonapi_url
56-
})
43+
RouterModule.forRoot(appRoutes, { useHash: true })
5744
],
5845
declarations: [AppComponent],
5946
bootstrap: [AppComponent]
6047
})
61-
export class AppModule {}
48+
export class AppModule {
49+
public constructor() {
50+
JsonapiBootstrap.bootstrap({ user_config: { url: environment.jsonapi_url } });
51+
}
52+
}

docs/migration-v2-to-v3.md

+84
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
# ngx-jsonapi v2 to v3 update guide
2+
3+
ngx-jsonapi v3 has arrived! While this is a major version change (from 2.x to 3.x), we've put in a lot of work to keep the hard breaking changes to a minimum.
4+
5+
## Library bootstrap
6+
7+
### Before
8+
9+
```typescript
10+
import { NgxJsonapiModule } from 'ngx-jsonapi';
11+
12+
@NgModule({
13+
imports: [
14+
NgxJsonapiModule.forRoot({
15+
url: '//jsonapiplayground.reyesoft.com/v2/'
16+
})
17+
]
18+
})
19+
export class AppModule {}
20+
```
21+
22+
#### Enable Local Cache
23+
24+
```typescrypt
25+
import { NgxJsonapiModule } from 'ngx-jsonapi';
26+
import { JSONAPI_RIPPER_SERVICE, JSONAPI_STORE_SERVICE } from './core';
27+
import { StoreService } from 'ngx-jsonapi/sources/store.service';
28+
import { JsonRipper } from 'ngx-jsonapi/services/json-ripper';
29+
30+
@NgModule({
31+
imports: [
32+
NgxJsonapiModule.forRoot({
33+
url: '//jsonapiplayground.reyesoft.com/v2/'
34+
})
35+
],
36+
providers: [
37+
{
38+
provide: JSONAPI_RIPPER_SERVICE,
39+
useClass: JsonRipperFake
40+
},
41+
{
42+
provide: JSONAPI_STORE_SERVICE,
43+
useClass: StoreFakeService
44+
}
45+
]
46+
})
47+
export class AppModule {}
48+
```
49+
50+
### After
51+
52+
```typescript
53+
/* .. */
54+
import { NgxJsonapiModule } from 'ngx-jsonapi';
55+
56+
@NgModule()
57+
export class AppModule {
58+
public constructor() {
59+
JsonapiBootstrap({
60+
user_config: { url: '//jsonapiplayground.reyesoft.com/v2/' }
61+
});
62+
}
63+
}
64+
```
65+
66+
#### Enable Local Cache
67+
68+
```typescript
69+
/* .. */
70+
import { NgxJsonapiModule } from 'ngx-jsonapi';
71+
import { StoreService } from 'ngx-jsonapi/sources/store.service';
72+
import { JsonRipper } from 'ngx-jsonapi/services/json-ripper';
73+
74+
@NgModule()
75+
export class AppModule {
76+
public constructor() {
77+
JsonapiBootstrap({
78+
user_config: { url: '//jsonapiplayground.reyesoft.com/v2/' },
79+
jsonapiStore: new StoreFakeService(),
80+
jsonRipper: new JsonRipperFake()
81+
});
82+
}
83+
}
84+
```

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,7 @@
151151
"zone.js": "~0.10.2"
152152
},
153153
"dependencies": {
154+
"axios": "^0.21.1",
154155
"dexie": "^2.0.4",
155156
"lodash-es": "^4.17.15",
156157
"rxjs": "6.6.7",

src/bootstraps/jsonapi-bootstrap.ts

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import { Core } from '../core';
2+
import { IBootstrapConfig } from '../interfaces/bootstrap-config';
3+
import { JsonapiConfig } from '../jsonapi-config';
4+
import { JsonRipperFake } from '../services/json-ripper-fake';
5+
import { Http } from '../sources/http.service';
6+
import { StoreFakeService } from '../sources/store-fake.service';
7+
8+
export class JsonapiBootstrap {
9+
public static bootstrap(bootstrapConfig: IBootstrapConfig): void {
10+
let config = new JsonapiConfig();
11+
12+
for (let k in config) {
13+
(<any>config)[k] = bootstrapConfig.user_config[k] !== undefined ? bootstrapConfig.user_config[k] : (<any>config)[k];
14+
}
15+
16+
Core.getInstance().injectedServices = {
17+
JsonapiStoreService: bootstrapConfig.jsonapiStore ? bootstrapConfig.jsonapiStore : new StoreFakeService(),
18+
JsonapiHttp: new Http(),
19+
json_ripper: bootstrapConfig.jsonRipper ? bootstrapConfig.jsonRipper : new JsonRipperFake(),
20+
rsJsonapiConfig: config
21+
};
22+
}
23+
}

src/cloned-document-resource.ts

+3-8
Original file line numberDiff line numberDiff line change
@@ -42,20 +42,15 @@ export class ClonedDocumentResource {
4242
}
4343
let parent_included = this.parent_resource_object.included;
4444
this.resource_object.included = this.resource_object.included.filter(included_resource => {
45-
return !isEqual(
46-
included_resource,
47-
parent_included.find(include => include.id === included_resource.id)
48-
);
45+
return !isEqual(included_resource, parent_included.find(include => include.id === included_resource.id));
4946
});
5047
this.resource_object.included = this.resource_object.included.map(included => {
5148
if (!parent_included.find(include => include.id === included.id)) {
5249
return included;
5350
}
5451

55-
return new ClonedDocumentResource(
56-
included,
57-
parent_included.find(include => include.id === included.id)
58-
).getResourceObject().data;
52+
return new ClonedDocumentResource(included, parent_included.find(include => include.id === included.id)).getResourceObject()
53+
.data;
5954
});
6055

6156
return this;

0 commit comments

Comments
 (0)