Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Experiment to see what's up with dispatch #4

Merged
merged 1 commit into from Nov 21, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
29 changes: 20 additions & 9 deletions app/scripts/actions/file.actions.ts
@@ -1,4 +1,4 @@
import { Injectable } from '@angular/core'
import { Injectable, NgZone } from '@angular/core'
import { NgRedux } from 'ng2-redux'
import { IAppState } from '../store'

Expand All @@ -13,7 +13,8 @@ interface IAction {
export class FileActions {
constructor (
private ngRedux: NgRedux<IAppState>,
private IPCService: IPCService) {}
private IPCService: IPCService,
private ngZone: NgZone) {}

static RECEIVE_ROOT_FILES: string = 'RECEIVE_ROOT_FILES'
static RECEIVE_CURRENT_FILE: string = 'RECEIVE_CURRENT_FILE'
Expand All @@ -34,7 +35,7 @@ export class FileActions {

getAllFiles (): void {
this.IPCService.sendMessage('files', '', (event, arg) => {
this.ngRedux.dispatch(FileActions.receiveAllFiles(arg.data))
this.zoneDispatch(FileActions.receiveAllFiles(arg.data))

return true
})
Expand All @@ -43,7 +44,7 @@ export class FileActions {
getDirFiles (dirName): void {
this.IPCService.sendMessage('files/dir', dirName, (event, arg) => {
if (arg.id === dirName) {
this.ngRedux.dispatch({
this.zoneDispatch({
type: FileActions.RECEIVE_DIR_FILES,
payload: {
files: arg.data
Expand All @@ -56,7 +57,7 @@ export class FileActions {
createFile (filePath: string): void {
this.IPCService.sendMessage('files/create', filePath, (event, arg) => {
if (arg.id === filePath) {
this.ngRedux.dispatch({
this.zoneDispatch({
type: FileActions.RECEIVE_NEW_FILE,
payload: arg
})
Expand All @@ -69,19 +70,19 @@ export class FileActions {
getCurrentFile (filePath: string): void {
this.IPCService.sendMessage('files/get', filePath, (event, arg) => {
if (arg.id === filePath) {
this.ngRedux.dispatch({
this.zoneDispatch({
type: FileActions.RECEIVE_CURRENT_FILE,
payload: arg
})

return true
}
})
});
}

saveCurrentFile (filePath: string, content: string): void {
console.log('WHOA', filePath, content)
this.ngRedux.dispatch({
this.zoneDispatch({
type: FileActions.SAVING_CURRENT_FILE,
payload: filePath
});
Expand All @@ -91,7 +92,7 @@ export class FileActions {
content
}, (event, arg) => {
if (arg.id === filePath) {
this.ngRedux.dispatch({
this.zoneDispatch({
type: FileActions.SAVED_CURRENT_FILE,
payload: {
content
Expand All @@ -100,4 +101,14 @@ export class FileActions {
}
})
}

private zoneDispatch(action) {
console.log('Am I in the Angular Zone?', NgZone.isInAngularZone(), action.type);
if (!NgZone.isInAngularZone()) {
this.ngZone.run(() => this.ngRedux.dispatch(action));
}
else {
this.ngRedux.dispatch(action);
}
}
}
19 changes: 15 additions & 4 deletions app/scripts/actions/settings.actions.ts
@@ -1,4 +1,4 @@
import { Injectable } from '@angular/core'
import { Injectable, NgZone } from '@angular/core'
import { NgRedux } from 'ng2-redux'
import { IAppState } from '../store'

Expand All @@ -11,14 +11,15 @@ export class SettingsActions {
constructor (
private ngRedux: NgRedux<IAppState>,
private IPCService: IPCService,
private fileActions: FileActions) {}
private fileActions: FileActions,
private ngZone: NgZone) {}

static SET_PATH: string = 'SET_PATH'
static GET_PATH: string = 'GET_PATH'

setPath (path): void {
this.IPCService.sendMessage('path/set', { path }, (event, arg) => {
this.ngRedux.dispatch({
this.zoneDispatch({
type: SettingsActions.SET_PATH,
payload: {
path
Expand All @@ -33,12 +34,22 @@ export class SettingsActions {

getPath (): void {
this.IPCService.sendMessage('path', '', (event, arg) => {
this.ngRedux.dispatch({
this.zoneDispatch({
type: SettingsActions.GET_PATH,
payload: {
path: arg.path
}
})
})
}

private zoneDispatch(action) {
console.log('Am I in the Angular Zone?', NgZone.isInAngularZone(), action.type);
if (!NgZone.isInAngularZone()) {
this.ngZone.run(() => this.ngRedux.dispatch(action));
}
else {
this.ngRedux.dispatch(action);
}
}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See my comments on angular-redux/store#259 for what's going on here.

}
2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -46,7 +46,7 @@
"redux": "3.6.0",
"reflect-metadata": "0.1.8",
"remove-markdown": "0.1.0",
"rxjs": "5.0.0-rc.3",
"rxjs": "5.0.0-beta.12",
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is incidental to the main problem - just fixing a peer dep warning.

"zone.js": "0.6.26"
},
"devDependencies": {
Expand Down