forked from ManageIQ/manageiq-ui-classic
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
New Provider form & controller improvements
Signed-off-by: Vojtech Szocs <vojtech.szocs@gmail.com>
- Loading branch information
1 parent
f57df76
commit 204bdff
Showing
6 changed files
with
79 additions
and
63 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,33 +1,32 @@ | ||
import { getStore, addReducer, applyReducerHash } from '../miq-redux/redux-client'; | ||
import { MiqStore, IMiqReducerHash, AppState, IMiqAction } from '../miq-redux/redux-types'; | ||
import { AppState, MiqStore, IMiqReducerHash, IMiqAction } from '../miq-redux/redux-types'; | ||
|
||
export interface IUnbindReduxReducers { | ||
redux?: () => void; | ||
interface IUnbindRedux { | ||
store?: () => void; | ||
reducer?: () => void; | ||
} | ||
|
||
export abstract class DefaultFormController { | ||
protected unbind: IUnbindReduxReducers = {}; | ||
protected reduxStore: MiqStore; | ||
protected store: MiqStore; | ||
private unbind: IUnbindRedux = {}; | ||
|
||
constructor(reducersHash?: IMiqReducerHash) { | ||
if (reducersHash) { | ||
constructor(reducers?: IMiqReducerHash) { | ||
this.store = getStore(); | ||
this.unbind.store = this.store.subscribe(() => this.updateFromStore()); | ||
|
||
if (reducers) { | ||
this.unbind.reducer = addReducer( | ||
(state: AppState, action: IMiqAction) => applyReducerHash(reducersHash, state, action) | ||
(state: AppState, action: IMiqAction) => applyReducerHash(reducers, state, action) | ||
); | ||
} | ||
this.reduxStore = getStore(); | ||
this.unbind.redux = this.reduxStore.subscribe(() => this.updateStore()); | ||
} | ||
|
||
protected updateStore() { | ||
throw new Error('Controller should implement updateStore method'); | ||
public updateFromStore() { | ||
throw new Error('Controller should implement updateFromStore method'); | ||
} | ||
|
||
public $onDestroy() { | ||
this.unbind.redux(); | ||
if (this.unbind.reducer) { | ||
this.unbind.reducer(); | ||
} | ||
this.unbind.store(); | ||
this.unbind.reducer && this.unbind.reducer(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
import NewProviderForm from './new'; | ||
import NewProviderForm from './new-provider'; | ||
|
||
ManageIQ.angular.app.component('newProviderForm', new NewProviderForm()); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import { IMiqAction } from '../../miq-redux/redux-types'; | ||
|
||
export const INIT_NEW_PROVIDER = 'INIT_NEW_PROVIDER_HAWKULAR' | ||
export const UPDATE_NEW_PROVIDER = 'UPDATE_NEW_PROVIDER_HAWKULAR'; | ||
|
||
export function initNewProvider(): IMiqAction { | ||
return { | ||
type: INIT_NEW_PROVIDER | ||
}; | ||
} | ||
|
||
export function updateNewProvider(payload: Object): IMiqAction { | ||
return { | ||
type: UPDATE_NEW_PROVIDER, | ||
payload | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters