-
Notifications
You must be signed in to change notification settings - Fork 26.8k
Closed
Description
I have a case where the automatic change detection is not working. I'm making an Electron app with multiple windows that send messages to one another via IPC. Here's some code:
(function(app) {
app.LinkListComponent = ng.core.Component({
selector: 'link-list'
, providers: [ app.FooService ]
, directives: [ ng.common.NgFor, ng.common.NgIf ]
, template: `
<ul>
<li *ngFor="#link of links">{{ link }}</li>
</ul>
<input type="button" value="Add link" (click)="addLink('this triggers <ul><li>... refresh')"/>
`
}).Class({
constructor: function(foo) {
this.links = foo.links; // Note: Same array reference as app.FooService instance
}, addLink: function(link) {
this.links.push(link);
}
});
app.LinkListComponent.parameters = [[ app.FooService ]];
})(window.app || (window.app = {}));Then elsewhere:
const links = []; // outside of FooService to force singleton (not sure if matters yet)
app.FooService = function() {
this.links = links;
this.open = function(url) {
initSubject(); // subject is an Electron BrowserWindow instance
subject.openDevTools();
subject.loadURL(url);
subject.show();
subject.webContents.addListener('ipc-message', (e, args) => {
const obj = args[0];
if (obj.type === 'links') {
// TODO: Keep stable sorted, figure out why _.clone() is necessary
const newLinks = _.clone(obj.links);
Array.prototype.push.apply(newLinks, links);
_.remove(links);
// this should trigger <ul><li>... refresh but it doesn't
Array.prototype.push.apply(links, _.uniq(newLinks));
return;
}
console.log(obj);
});
};
};baileyisms
Metadata
Metadata
Assignees
Labels
No labels