@ima/core
Version:
IMA.js framework for isomorphic javascript application
228 lines (227 loc) • 9.65 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
Object.defineProperty(exports, "initBind", {
enumerable: true,
get: function() {
return initBind;
}
});
const _helpers = /*#__PURE__*/ _interop_require_wildcard(require("@ima/helpers"));
const _Cache = require("../cache/Cache");
const _CacheFactory = require("../cache/CacheFactory");
const _CacheImpl = require("../cache/CacheImpl");
const _ControllerDecorator = require("../controller/ControllerDecorator");
const _Dictionary = require("../dictionary/Dictionary");
const _MessageFormatDictionary = require("../dictionary/MessageFormatDictionary");
const _GenericError = require("../error/GenericError");
const _Dispatcher = require("../event/Dispatcher");
const _DispatcherImpl = require("../event/DispatcherImpl");
const _EventBus = require("../event/EventBus");
const _EventBusImpl = require("../event/EventBusImpl");
const _Observable = require("../event/Observable");
const _ObservableImpl = require("../event/ObservableImpl");
const _HttpAgent = require("../http/HttpAgent");
const _HttpAgentImpl = require("../http/HttpAgentImpl");
const _HttpProxy = require("../http/HttpProxy");
const _HttpStatusCode = require("../http/HttpStatusCode");
const _UrlTransformer = require("../http/UrlTransformer");
const _MetaManager = require("../meta/MetaManager");
const _MetaManagerImpl = require("../meta/MetaManagerImpl");
const _PageHandlerRegistry = require("../page/handler/PageHandlerRegistry");
const _PageMetaHandler = require("../page/handler/PageMetaHandler");
const _PageNavigationHandler = require("../page/handler/PageNavigationHandler");
const _ClientPageManager = require("../page/manager/ClientPageManager");
const _PageManager = require("../page/manager/PageManager");
const _ServerPageManager = require("../page/manager/ServerPageManager");
const _PageFactory = require("../page/PageFactory");
const _ComponentUtils = require("../page/renderer/ComponentUtils");
const _PageStateManager = require("../page/state/PageStateManager");
const _PageStateManagerDecorator = require("../page/state/PageStateManagerDecorator");
const _PageStateManagerImpl = require("../page/state/PageStateManagerImpl");
const _ClientRouter = require("../router/ClientRouter");
const _Request = require("../router/Request");
const _Response = require("../router/Response");
const _RouteFactory = require("../router/RouteFactory");
const _RouteNames = require("../router/RouteNames");
const _Router = require("../router/Router");
const _RouterEvents = require("../router/RouterEvents");
const _ServerRouter = require("../router/ServerRouter");
const _CookieStorage = require("../storage/CookieStorage");
const _MapStorage = require("../storage/MapStorage");
const _SessionMapStorage = require("../storage/SessionMapStorage");
const _SessionStorage = require("../storage/SessionStorage");
const _WeakMapStorage = require("../storage/WeakMapStorage");
const _ClientWindow = require("../window/ClientWindow");
const _ServerWindow = require("../window/ServerWindow");
const _Window = require("../window/Window");
function _getRequireWildcardCache(nodeInterop) {
if (typeof WeakMap !== "function") return null;
var cacheBabelInterop = new WeakMap();
var cacheNodeInterop = new WeakMap();
return (_getRequireWildcardCache = function(nodeInterop) {
return nodeInterop ? cacheNodeInterop : cacheBabelInterop;
})(nodeInterop);
}
function _interop_require_wildcard(obj, nodeInterop) {
if (!nodeInterop && obj && obj.__esModule) {
return obj;
}
if (obj === null || typeof obj !== "object" && typeof obj !== "function") {
return {
default: obj
};
}
var cache = _getRequireWildcardCache(nodeInterop);
if (cache && cache.has(obj)) {
return cache.get(obj);
}
var newObj = {
__proto__: null
};
var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor;
for(var key in obj){
if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) {
var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null;
if (desc && (desc.get || desc.set)) {
Object.defineProperty(newObj, key, desc);
} else {
newObj[key] = obj[key];
}
}
}
newObj.default = obj;
if (cache) {
cache.set(obj, newObj);
}
return newObj;
}
const initBind = (ns, oc, config)=>{
oc.constant('$Helper', _helpers);
oc.constant('$oc', oc);
oc.constant('$Settings', config);
oc.constant('$Env', config.$Env);
oc.constant('$Protocol', config.$Protocol);
oc.constant('$Secure', config.$Protocol === 'https:');
// Request & Response
oc.bind('$Request', _Request.Request);
oc.bind('$Response', _Response.Response);
// Window helper
if (typeof window !== 'undefined' && window !== null) {
oc.provide(_Window.Window, _ClientWindow.ClientWindow);
} else {
oc.provide(_Window.Window, _ServerWindow.ServerWindow);
}
oc.bind('$Window', _Window.Window);
oc.bind('$Error', _GenericError.GenericError);
// Dictionary
oc.provide(_Dictionary.Dictionary, _MessageFormatDictionary.MessageFormatDictionary);
oc.bind('$Dictionary', _Dictionary.Dictionary);
// Storage
oc.constant('$CookieTransformFunction', {
encode: (s)=>s,
decode: (s)=>s
});
oc.bind('$CookieStorage', _CookieStorage.CookieStorage);
if (oc.get(_Window.Window).hasSessionStorage()) {
oc.bind('$SessionStorage', _SessionStorage.SessionStorage);
} else {
oc.bind('$SessionStorage', _MapStorage.MapStorage);
}
oc.bind('$MapStorage', _MapStorage.MapStorage);
oc.inject(_WeakMapStorage.WeakMapStorage, [
{
entryTtl: 30 * 60 * 1000,
maxEntries: 1000,
gcInterval: 60 * 1000,
gcEntryCountTreshold: 16
}
]);
oc.bind('$WeakMapStorage', _WeakMapStorage.WeakMapStorage);
oc.bind('$SessionMapStorage', _SessionMapStorage.SessionMapStorage);
// Dispatcher
oc.provide(_Dispatcher.Dispatcher, _DispatcherImpl.DispatcherImpl);
oc.bind('$Dispatcher', _Dispatcher.Dispatcher);
// Custom Event Bus
oc.provide(_EventBus.EventBus, _EventBusImpl.EventBusImpl);
oc.bind('$EventBus', _EventBus.EventBus);
// Observable
oc.provide(_Observable.Observable, _ObservableImpl.ObservableImpl);
oc.bind('$Observable', _Observable.Observable);
// Cache
oc.constant('$CacheStorage', oc.get(_MapStorage.MapStorage));
oc.bind('$CacheFactory', _CacheFactory.CacheFactory);
oc.provide(_Cache.Cache, _CacheImpl.CacheImpl, [
'$CacheStorage',
_CacheFactory.CacheFactory,
'$Helper',
config.$Cache || {}
]);
oc.bind('$Cache', _Cache.Cache);
// SEO
oc.provide(_MetaManager.MetaManager, _MetaManagerImpl.MetaManagerImpl);
oc.bind('$MetaManager', _MetaManager.MetaManager);
oc.bind('$ControllerDecorator', _ControllerDecorator.ControllerDecorator);
oc.bind('$PageStateManagerDecorator', _PageStateManagerDecorator.PageStateManagerDecorator);
// Page
oc.provide(_PageStateManager.PageStateManager, _PageStateManagerImpl.PageStateManagerImpl);
oc.bind('$PageStateManager', _PageStateManager.PageStateManager);
oc.inject(_PageFactory.PageFactory, [
oc
]);
oc.bind('$PageFactory', _PageFactory.PageFactory);
oc.inject(_ComponentUtils.ComponentUtils, [
oc
]);
oc.bind('$ComponentUtils', _ComponentUtils.ComponentUtils);
oc.get(_ComponentUtils.ComponentUtils).register({
$Dictionary: _Dictionary.Dictionary,
$Dispatcher: _Dispatcher.Dispatcher,
$EventBus: _EventBus.EventBus,
$Observable: _Observable.Observable,
$Helper: '$Helper',
$Http: _HttpAgent.HttpAgent,
$PageStateManager: _PageStateManager.PageStateManager,
$Router: _Router.Router,
$Settings: '$Settings',
$Window: _Window.Window
});
if (oc.get(_Window.Window).isClient()) {
oc.bind('$PageHandlerRegistry', _PageHandlerRegistry.PageHandlerRegistry, [
_PageNavigationHandler.PageNavigationHandler,
_PageMetaHandler.PageMetaHandler
]);
oc.provide(_PageManager.PageManager, _ClientPageManager.ClientPageManager);
} else {
oc.bind('$PageHandlerRegistry', _PageHandlerRegistry.PageHandlerRegistry, []);
oc.provide(_PageManager.PageManager, _ServerPageManager.ServerPageManager);
}
oc.bind('$PageManager', _PageManager.PageManager);
// Router
oc.bind('$RouteFactory', _RouteFactory.RouteFactory);
if (oc.get(_Window.Window).isClient()) {
oc.provide(_Router.Router, _ClientRouter.ClientRouter);
} else {
oc.provide(_Router.Router, _ServerRouter.ServerRouter);
}
oc.bind('$Router', _Router.Router);
oc.constant('$RouteNames', _RouteNames.RouteNames);
oc.constant('$RouterEvents', _RouterEvents.RouterEvents);
// Http agent
oc.bind('$HttpUrlTransformer', _UrlTransformer.UrlTransformer);
oc.bind('$HttpAgentProxy', _HttpProxy.HttpProxy, [
'$HttpUrlTransformer',
'$Window'
]);
oc.provide(_HttpAgent.HttpAgent, _HttpAgentImpl.HttpAgentImpl, [
'$HttpAgentProxy',
'$Cache',
_CookieStorage.CookieStorage,
config.$Http,
'$Helper'
]);
oc.bind('$Http', _HttpAgent.HttpAgent);
oc.constant('$HttpStatusCode', _HttpStatusCode.HttpStatusCode);
};
//# sourceMappingURL=bind.js.map