Implementing a Users Collection - ldco2016/microurb_web_framework GitHub Wiki
import { User } from "./User";
export class Collection {
models: User[] = [];
}
The next thing I want to do is wire up the Eventing module to broadcast a signal out to the rest of my application anytime I have successfully fetched some data like so:
import { User } from "./User";
import { Eventing } from "./Eventing";
export class Collection {
models: User[] = [];
events: Eventing = new Eventing();
}
In the case of Eventing
, I probably just want setup some pass through methods with this thing and ensure that other locations in the code can directly call on()
and trigger on collection like so:
import { User } from "./User";
import { Eventing } from "./Eventing";
export class Collection {
models: User[] = [];
events: Eventing = new Eventing();
get on() {
return this.events.on;
}
}
Why not use the shortened syntax of on = this.events.on;
?
If I am initializing a property in the above fashion, this line of code events: Eventing = new Eventing();
, will run after on = this.events.on;
and so I cannot use that shortened syntax if I am initializing properties inline, so thats why I am using a getter to expose on()
to the outside world.
Lastly, I need trigger()
:
import { User } from "./User";
import { Eventing } from "./Eventing";
export class Collection {
models: User[] = [];
events: Eventing = new Eventing();
get on() {
return this.events.on;
}
get trigger() {
return this.events.trigger;
}
}