Skip to content

Commit 92d0dca

Browse files
author
Jonathan Casarrubias
committed
Release 2.1.0-beta.3 🚀
- Fix: #131 - Fix: #130 - Fix: #129
1 parent d9b34a1 commit 92d0dca

27 files changed

Lines changed: 201 additions & 87 deletions

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,12 @@
22

33
This file is created to keep history of the LoopBack SDK Builder, it does not consider or keeps any history of its parent module `loopback-sdk-angular`.
44

5+
## Release 2.1.0-beta.3
6+
7+
- Fix: https://github.com/mean-expert-official/loopback-sdk-builder/issues/131
8+
- Fix: https://github.com/mean-expert-official/loopback-sdk-builder/issues/130
9+
- Fix: https://github.com/mean-expert-official/loopback-sdk-builder/issues/129
10+
511
## Release 2.1.0-beta.2
612

713
- Hot Fix: https://github.com/mean-expert-official/loopback-sdk-builder/issues/128

bin/lb-sdk

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,11 @@ var argv = optimist
2525
'\n ./node_modules/.bin/lb-sdk server/server app/shared/sdk -d [ng4web | nativescript2] -i [enabled | disabled]')
2626
.describe('l', 'Client\'s library (angular2, react <todo>, ...)')
2727
.describe('d', 'Platform specific drivers (ng4web, nativescript2, ng2universal <todo>)')
28-
.describe('i', 'Enable PubSub functionality for loopback-component-pubsub')
28+
.describe('i', 'Enable PubSub, IO and FireLoop functionality')
2929
.describe('w', 'Automatically wipe SDK Directory')
3030
.default('l', 'angular2')
3131
.default('d', 'ng4web')
32-
.default('i', 'disabled')
32+
.default('i', 'enabled')
3333
.default('w', 'disabled')
3434
.alias({ u: 'url', m: 'module-name', l: 'library', i: 'io', d: 'driver', w: 'wipe' })
3535
.demand(1)

lib/angular2/index.js

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,10 @@ module.exports = function generate(ctx) {
6262
{
6363
template: './shared/models/index.ejs',
6464
output: '/models/index.ts',
65-
params: { models: ctx.models }
65+
params: {
66+
isIo: ctx.isIo,
67+
models: ctx.models
68+
}
6669
},
6770
{
6871
template: './shared/services/index.ejs',
@@ -163,8 +166,13 @@ module.exports = function generate(ctx) {
163166
params: {}
164167
},
165168
{
166-
template: './shared/services/core/fireloop.ejs',
167-
output: '/services/core/fireloop.ts',
169+
template: './shared/models/fireloop.ejs',
170+
output: '/models/FireLoop.ts',
171+
params: {}
172+
},
173+
{
174+
template: './shared/models/flref.ejs',
175+
output: '/models/FireLoopRef.ts',
168176
params: {}
169177
}
170178
]);
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import { LoopBackConfig } from '../lb.config';
2+
import { AccessToken, FireLoopRef } from './index';
3+
import { SocketConnections } from '../sockets/socket.connections';
4+
5+
export class FireLoop {
6+
7+
private socket: any;
8+
private references: any = {};
9+
10+
constructor(token: AccessToken) {
11+
this.socket = SocketConnections.getHandler(LoopBackConfig.getPath(), token);
12+
}
13+
14+
public ref<T>(model: { getModelName(): string }): FireLoopRef<T> {
15+
let name: string = model.getModelName();
16+
if (this.references[name]) { return this.references[name]; }
17+
this.references[name] = new FireLoopRef<T>(name, this.socket);
18+
return this.references[name];
19+
}
20+
}
Lines changed: 15 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,26 @@
11
import { Subject } from 'rxjs/Subject';
22
import { Observable } from 'rxjs/Observable';
3-
import { LoopBackConfig } from '../../lb.config';
4-
import { AccessToken, LoopBackFilter } from '../../models';
5-
import { SocketConnections } from '../../sockets/socket.connections';
3+
import { LoopBackConfig } from '../lb.config';
4+
import { AccessToken, LoopBackFilter } from './index';
5+
import { SocketConnections } from '../sockets/socket.connections';
66

7-
class Reference {
7+
export class FireLoopRef<T> {
88

99
private instance: any;
1010
private socket: any;
1111
private name: string;
12-
private parent: Reference;
12+
private parent: FireLoopRef<T>;
1313
private childs: any = {};
1414
private observables: any = {};
1515

16-
constructor(name: string, socket: any, parent: Reference = null) {
16+
constructor(name: string, socket: any, parent: FireLoopRef<any> = null) {
1717
this.name = name;
1818
this.parent = parent;
1919
this.socket = socket;
2020
return this;
2121
}
2222

23-
public upsert(data: any): Observable<any> {
23+
public upsert(data: any): Observable<T> {
2424
let id: number = Math.floor(Math.random() * 100800) *
2525
Math.floor(Math.random() * 100700) *
2626
Math.floor(Math.random() * 198500);
@@ -32,18 +32,18 @@ class Reference {
3232
parent : this.parent && this.parent.instance ? this.parent.instance : null
3333
}
3434
};
35-
let subject: Subject<any> = new Subject<any>();
35+
let subject: Subject<T> = new Subject<T>();
3636
this.socket.emit('ME:RT:1://event', request);
3737
this.socket.on(`${this.name}.value.result.${id}`, (res: any) =>
3838
subject.next(res.error ? Observable.throw(res.error) : res)
3939
);
4040
return subject.asObservable();
4141
}
4242

43-
public on(event: string, filter: LoopBackFilter = { limit: 100 }): Observable<any> {
43+
public on(event: string, filter: LoopBackFilter = { limit: 100 }): Observable<T | T[]> {
4444
event = `${this.name}.${event}`;
4545
if (this.observables[event]) { return this.observables[event]; }
46-
let subject: Subject<any> = new Subject<any>();
46+
let subject: Subject<T> = new Subject<T>();
4747
if (event.match(/(value)/))
4848
this.pull(event, filter, subject);
4949
// Listen for broadcast announces
@@ -59,41 +59,25 @@ class Reference {
5959
return this.observables[event];
6060
}
6161

62-
private pull(event: string, filter: any, subject: Subject<any>): void {
62+
private pull(event: string, filter: any, subject: Subject<T>): void {
6363
this.socket.emit(`${event}.pull.request`, filter);
6464
this.socket.on(`${event}.pull.requested`, (res: any) => subject.next(res));
6565
}
6666

67-
public make(instance: any): Reference {
67+
public make(instance: any): FireLoopRef<T> {
6868
this.instance = instance;
6969
return this;
7070
}
7171

72-
public child(name: string): Reference {
72+
public child<T>(name: string): FireLoopRef<T> {
7373
if (!this.parent) {
7474
let childName = `${this.name}.${name}`;
7575
if (this.childs[childName]) { return this.childs[childName]; }
76-
this.childs[childName] = new Reference(childName, this.socket, this);
76+
this.childs[childName] = new FireLoopRef<T>(childName, this.socket, this);
7777
return this.childs[childName];
7878
} else {
7979
console.warn('Only 1 child level is supported');
8080
// TODO ADD UNLIMITED LEVELS
8181
}
8282
}
83-
}
84-
85-
export class FireLoop {
86-
87-
private socket: any;
88-
private references: any = {};
89-
90-
constructor(token: AccessToken) {
91-
this.socket = SocketConnections.getHandler(LoopBackConfig.getPath(), token);
92-
}
93-
94-
public ref(name: string): Reference {
95-
if (this.references[name]) { return this.references[name]; }
96-
this.references[name] = new Reference(name, this.socket);
97-
return this.references[name];
98-
}
99-
}
83+
}

lib/angular2/shared/models/index.ejs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,6 @@
77
export * from './<%- modelName %>';
88
<% } // for modelName in models -%>
99
export * from './BaseModels';
10+
<% if ( isIo === 'enabled' ){ -%>export * from './FireLoopRef';
11+
<% }
12+
-%>

lib/angular2/shared/models/model.ejs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,11 @@ export class <%- modelName %> implements <%- modelName %>Interface {
1010
constructor(instance?: <%- modelName %>Interface) {
1111
Object.assign(this, instance);
1212
}
13+
/**
14+
* The name of the model represented by this $resource,
15+
* i.e. `<%- modelName %>`.
16+
*/
17+
public static getModelName() {
18+
return <%-: modelName | q %>;
19+
}
1320
}

lib/angular2/shared/services/core/realtime.ejs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import { Injectable, Inject } from '@angular/core';
22
import { IO } from './io.service';
3-
import { FireLoop } from './fireloop';
43
import { JSONSearchParams } from './search.params';
54
import { LoopBackAuth } from './auth.service';
65
import { AccessToken } from '../../models';
6+
import { FireLoop } from '../../models/FireLoop';
77

88
@Injectable()
99
export class RealTime {

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@mean-expert/loopback-sdk-builder",
3-
"version": "2.1.0-beta.2",
3+
"version": "2.1.0-beta.3",
44
"description": "Tool for auto-generating Software Development Kits (SDKs) for LoopBack",
55
"bin": {
66
"lb-sdk": "bin/lb-sdk"

tests/angular2/loopback/component-config.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"mountPath": "/explorer"
44
},
55
"@mean-expert/loopback-component-realtime": {
6-
"debug": true,
6+
"debug": false,
77
"auth": false
88
}
99
}

0 commit comments

Comments
 (0)