mirror of
https://github.com/the-djmaze/snappymail.git
synced 2026-07-13 03:27:39 +03:00
Code refactoring
Flow first look
This commit is contained in:
parent
2f841524cb
commit
e6e0b02849
71 changed files with 2092 additions and 1836 deletions
|
|
@ -4,13 +4,15 @@ import {isArray, disposeObject} from 'Common/Utils';
|
|||
|
||||
class AbstractModel
|
||||
{
|
||||
sModelName = '';
|
||||
disposables = [];
|
||||
|
||||
/**
|
||||
* @param {string} modelName
|
||||
* @param {string} modelName = ''
|
||||
*/
|
||||
constructor(modelName)
|
||||
constructor(modelName = '')
|
||||
{
|
||||
this.sModelName = modelName || '';
|
||||
this.disposables = [];
|
||||
}
|
||||
|
||||
regDisposables(value) {
|
||||
|
|
|
|||
|
|
@ -5,9 +5,12 @@ import {isArray, isNonEmptyArray, noop} from 'Common/Utils';
|
|||
|
||||
class AbstractScreen
|
||||
{
|
||||
oCross = null;
|
||||
sScreenName;
|
||||
aViewModels;
|
||||
|
||||
constructor(screenName, viewModels = [])
|
||||
{
|
||||
this.oCross = null;
|
||||
this.sScreenName = screenName;
|
||||
this.aViewModels = isArray(viewModels) ? viewModels : [];
|
||||
}
|
||||
|
|
@ -54,8 +57,11 @@ class AbstractScreen
|
|||
fMatcher = _.bind(this.onRoute || noop, this);
|
||||
route = crossroads.create();
|
||||
|
||||
_.each(routes, (aItem) => {
|
||||
route.addRoute(aItem[0], fMatcher).rules = aItem[1];
|
||||
_.each(routes, (item) => {
|
||||
if (item && route)
|
||||
{
|
||||
route.addRoute(item[0], fMatcher).rules = item[1];
|
||||
}
|
||||
});
|
||||
|
||||
this.oCross = route;
|
||||
|
|
|
|||
|
|
@ -7,18 +7,16 @@ import {$win, keyScope} from 'Common/Globals';
|
|||
|
||||
class AbstractViewNext
|
||||
{
|
||||
constructor() {
|
||||
this.bDisabeCloseOnEsc = false;
|
||||
this.sDefaultKeyScope = KeyState.None;
|
||||
this.sCurrentKeyScope = this.sDefaultKeyScope;
|
||||
bDisabeCloseOnEsc = false;
|
||||
sDefaultKeyScope = KeyState.None;
|
||||
sCurrentKeyScope = KeyState.None;
|
||||
|
||||
this.viewModelVisibility = ko.observable(false);
|
||||
this.modalVisibility = ko.observable(false).extend({rateLimit: 0});
|
||||
viewModelVisibility = ko.observable(false);
|
||||
modalVisibility = ko.observable(false).extend({rateLimit: 0});
|
||||
|
||||
this.viewModelName = '';
|
||||
this.viewModelNames = [];
|
||||
this.viewModelDom = null;
|
||||
}
|
||||
viewModelName = '';
|
||||
viewModelNames = [];
|
||||
viewModelDom = null;
|
||||
|
||||
/**
|
||||
* @returns {void}
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@ import {$html, aViewModels as VIEW_MODELS, popupVisibilityNames} from 'Common/Gl
|
|||
|
||||
import {
|
||||
isArray, isUnd, pString, log, isFunc,
|
||||
createCommand, delegateRun, isNonEmptyArray
|
||||
createCommandLegacy, delegateRun, isNonEmptyArray
|
||||
} from 'Common/Utils';
|
||||
|
||||
let
|
||||
|
|
@ -35,6 +35,16 @@ export function hideLoading()
|
|||
$('#rl-loading').hide().remove();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {Function} fExecute
|
||||
* @param {(Function|boolean|null)=} fCanExecute = true
|
||||
* @returns {Function}
|
||||
*/
|
||||
export function createCommand(fExecute, fCanExecute = true)
|
||||
{
|
||||
return createCommandLegacy(null, fExecute, fCanExecute);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {Function} SettingsViewModelClass
|
||||
* @param {string} template
|
||||
|
|
@ -98,15 +108,35 @@ export function screen(screenName)
|
|||
return ('' !== screenName && !isUnd(SCREENS[screenName])) ? SCREENS[screenName] : null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {Function} ViewModelClassToShow
|
||||
* @returns {Function|null}
|
||||
*/
|
||||
export function getScreenPopup(PopuViewModelClass)
|
||||
{
|
||||
let result = null;
|
||||
if (PopuViewModelClass)
|
||||
{
|
||||
result = PopuViewModelClass;
|
||||
if (PopuViewModelClass.default)
|
||||
{
|
||||
result = PopuViewModelClass.default;
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {Function} ViewModelClassToHide
|
||||
* @returns {void}
|
||||
*/
|
||||
export function hideScreenPopup(ViewModelClassToHide)
|
||||
{
|
||||
if (ViewModelClassToHide && ViewModelClassToHide.__vm && ViewModelClassToHide.__dom)
|
||||
const ModalView = getScreenPopup(ViewModelClassToHide);
|
||||
if (ModalView && ModalView.__vm && ModalView.__dom)
|
||||
{
|
||||
ViewModelClassToHide.__vm.modalVisibility(false);
|
||||
ModalView.__vm.modalVisibility(false);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -231,19 +261,20 @@ export function buildViewModel(ViewModelClass, vmScreen)
|
|||
*/
|
||||
export function showScreenPopup(ViewModelClassToShow, params = [])
|
||||
{
|
||||
if (ViewModelClassToShow)
|
||||
const ModalView = getScreenPopup(ViewModelClassToShow);
|
||||
if (ModalView)
|
||||
{
|
||||
buildViewModel(ViewModelClassToShow);
|
||||
buildViewModel(ModalView);
|
||||
|
||||
if (ViewModelClassToShow.__vm && ViewModelClassToShow.__dom)
|
||||
if (ModalView.__vm && ModalView.__dom)
|
||||
{
|
||||
delegateRun(ViewModelClassToShow.__vm, 'onBeforeShow', params || []);
|
||||
delegateRun(ModalView.__vm, 'onBeforeShow', params || []);
|
||||
|
||||
ViewModelClassToShow.__vm.modalVisibility(true);
|
||||
ModalView.__vm.modalVisibility(true);
|
||||
|
||||
delegateRun(ViewModelClassToShow.__vm, 'onShow', params || []);
|
||||
delegateRun(ModalView.__vm, 'onShow', params || []);
|
||||
|
||||
vmRunHook('view-model-on-show', ViewModelClassToShow, params || []);
|
||||
vmRunHook('view-model-on-show', ModalView, params || []);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -254,13 +285,14 @@ export function showScreenPopup(ViewModelClassToShow, params = [])
|
|||
*/
|
||||
export function warmUpScreenPopup(ViewModelClassToShow)
|
||||
{
|
||||
if (ViewModelClassToShow)
|
||||
const ModalView = getScreenPopup(ViewModelClassToShow);
|
||||
if (ModalView)
|
||||
{
|
||||
buildViewModel(ViewModelClassToShow);
|
||||
buildViewModel(ModalView);
|
||||
|
||||
if (ViewModelClassToShow.__vm && ViewModelClassToShow.__dom)
|
||||
if (ModalView.__vm && ModalView.__dom)
|
||||
{
|
||||
delegateRun(ViewModelClassToShow.__vm, 'onWarmUp');
|
||||
delegateRun(ModalView.__vm, 'onWarmUp');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -271,7 +303,8 @@ export function warmUpScreenPopup(ViewModelClassToShow)
|
|||
*/
|
||||
export function isPopupVisible(ViewModelClassToShow)
|
||||
{
|
||||
return ViewModelClassToShow && ViewModelClassToShow.__vm ? ViewModelClassToShow.__vm.modalVisibility() : false;
|
||||
const ModalView = getScreenPopup(ViewModelClassToShow);
|
||||
return ModalView && ModalView.__vm ? ModalView.__vm.modalVisibility() : false;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -394,7 +427,7 @@ export function screenOnRoute(screenName, subPart)
|
|||
}
|
||||
// --
|
||||
|
||||
cross = vmScreen.__cross ? vmScreen.__cross() : null;
|
||||
cross = vmScreen && vmScreen.__cross ? vmScreen.__cross() : null;
|
||||
if (cross)
|
||||
{
|
||||
cross.parse(subPart);
|
||||
|
|
@ -515,6 +548,15 @@ function viewDecorator({name, type, templateID})
|
|||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {Object} params
|
||||
* @returns {Function}
|
||||
*/
|
||||
function popupDecorator({name, templateID})
|
||||
{
|
||||
return viewDecorator({name, type: ViewType.Popup, templateID});
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {Function} canExecute
|
||||
* @returns {Function}
|
||||
|
|
@ -548,4 +590,8 @@ function commandDecorator(canExecute = true)
|
|||
};
|
||||
}
|
||||
|
||||
export {commandDecorator, commandDecorator as command, viewDecorator, viewDecorator as view, viewDecorator as viewModel};
|
||||
export {
|
||||
commandDecorator, commandDecorator as command,
|
||||
viewDecorator, viewDecorator as view, viewDecorator as viewModel,
|
||||
popupDecorator, popupDecorator as popup
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue