calculo de modelos dependientes de manera asíncrona
This commit is contained in:
parent
4d6ad1a910
commit
8c88988ebf
|
@ -35,7 +35,7 @@ export const graphRoutes = {
|
|||
],
|
||||
|
||||
graphDependendies: {
|
||||
compras:["crud"],
|
||||
crud:[]
|
||||
compras: ["crud"],
|
||||
crud: []
|
||||
}
|
||||
};
|
|
@ -1,34 +1,33 @@
|
|||
import * as core from '@salix/core';
|
||||
|
||||
import * as spliting from './spliting';
|
||||
import {routes} from './fake';
|
||||
import * as routes from './fake';
|
||||
|
||||
core.module.config(function($stateProvider, $urlRouterProvider) {
|
||||
|
||||
|
||||
core.splitingRegister.registerGraph('hello');
|
||||
core.module.config(function ($stateProvider, $urlRouterProvider) {
|
||||
|
||||
function xxx(route){
|
||||
return function loader($ocLazyLoad, $q){
|
||||
core.splitingRegister.registerGraph(routes.graphRoutes.graphDependendies);
|
||||
|
||||
function loader(route) {
|
||||
return function loader($ocLazyLoad, $q) {
|
||||
return $q((resolve) => {
|
||||
core.splitingRegister.execute(route.module)
|
||||
spliting[route.module](() => {
|
||||
//resolve($ocLazyLoad.load({name: route.module}));
|
||||
|
||||
});
|
||||
core.splitingRegister.execute(route.module).then(function(dependencies){
|
||||
var array = dependencies.map((item) => { return { name: item } });
|
||||
resolve($ocLazyLoad.load(array));
|
||||
});
|
||||
});
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
$urlRouterProvider.otherwise("/");
|
||||
|
||||
routes.forEach(function(route) {
|
||||
|
||||
routes.graphRoutes.routes.forEach(function (route) {
|
||||
$stateProvider.state(route.state, {
|
||||
url: route.url,
|
||||
template :route.template,
|
||||
template: route.template,
|
||||
resolve: {
|
||||
loader: xxx(route)
|
||||
loader: loader(route)
|
||||
}
|
||||
})
|
||||
}, this);
|
||||
})
|
||||
}, this);
|
||||
});
|
||||
|
|
|
@ -1,21 +1,28 @@
|
|||
import * as core from '@salix/core';
|
||||
|
||||
|
||||
|
||||
export const compras = (cb) => {
|
||||
require.ensure([], () => {
|
||||
require('@salix/compras')
|
||||
cb();
|
||||
}, "salix.compras");
|
||||
export const compras = () => {
|
||||
return new Promise(resolve => {
|
||||
require.ensure([], () => {
|
||||
require('@salix/compras');
|
||||
resolve('compras');
|
||||
}, "salix.compras");
|
||||
});
|
||||
};
|
||||
|
||||
core.splitingRegister.register('compras', compras);
|
||||
|
||||
export const ventas = () => {
|
||||
require.ensure([], () => {
|
||||
require('@salix/ventas')
|
||||
}, "salix.ventas");
|
||||
};
|
||||
|
||||
core.splitingRegister.register('ventas', ventas);
|
||||
|
||||
export const pagos = () => {
|
||||
require.ensure([], () => {
|
||||
require('@salix/pagos')
|
||||
}, "salix.pagos");
|
||||
};
|
||||
|
||||
core.splitingRegister.register('pagos', pagos);
|
||||
|
|
|
@ -1,4 +1 @@
|
|||
import * as core from '@salix/core'
|
||||
import * as vendors from '@salix/vendor'
|
||||
import * as crud from '@salix/crud'
|
||||
console.log('compras');
|
||||
export * from './src/compras';
|
|
@ -0,0 +1 @@
|
|||
export * from './spliting';
|
|
@ -0,0 +1,12 @@
|
|||
import * as core from '@salix/core';
|
||||
|
||||
export const crud = () => {
|
||||
return new Promise(resolve => {
|
||||
require.ensure([], () => {
|
||||
require('@salix/crud');
|
||||
resolve('crud');
|
||||
}, "salix.crud");
|
||||
});
|
||||
};
|
||||
|
||||
core.splitingRegister.register('crud', crud);
|
|
@ -1,32 +1,59 @@
|
|||
const _SplitingRegister = ()=>{
|
||||
const _SplitingRegister = () => {
|
||||
|
||||
var _graph;
|
||||
var dependencies = {};
|
||||
|
||||
function getDependencies(dependency) {
|
||||
var array = [];
|
||||
array.push(dependency);
|
||||
var first = _graph[dependency];
|
||||
|
||||
while (first && first.length > 0) {
|
||||
dependency = first.shift();
|
||||
array = array.concat(getDependencies(dependency));
|
||||
}
|
||||
return array;
|
||||
}
|
||||
|
||||
return {
|
||||
registerGraph: function(graph){
|
||||
registerGraph: function (graph) {
|
||||
_graph = graph;
|
||||
},
|
||||
register: function(dependency,loader){
|
||||
dependencies[dependecy]=loader;
|
||||
register: function (dependency, loader) {
|
||||
dependencies[dependency] = loader;
|
||||
},
|
||||
execute: function(dependency){
|
||||
|
||||
var _array=[];
|
||||
_array.push(dependency);
|
||||
var fist =graph[dependency];
|
||||
execute: function (dependency) {
|
||||
return new Promise(resolve => {
|
||||
|
||||
//TODO:create dependy graph
|
||||
var array = getDependencies(dependency);
|
||||
var arrayClone = array.concat([]);
|
||||
|
||||
function getDependency() {
|
||||
var key = array.shift();
|
||||
return dependencies[key];
|
||||
}
|
||||
|
||||
(function loadDependency(dependency) {
|
||||
|
||||
if(!dependency){
|
||||
resolve(arrayClone);
|
||||
return;
|
||||
}
|
||||
dependency().then(function (data) {
|
||||
var _dependency = getDependency();
|
||||
loadDependency(_dependency);
|
||||
});
|
||||
} (getDependency()))
|
||||
|
||||
});
|
||||
|
||||
|
||||
while(key=array.pop()){
|
||||
dependencies[key]();
|
||||
}
|
||||
|
||||
},
|
||||
write:function(){
|
||||
|
||||
write: function () {
|
||||
console.log(_graph);
|
||||
}
|
||||
}
|
||||
};
|
||||
export const SplitingRegister = _SplitingRegister();
|
||||
window.dependencies = _SplitingRegister();
|
||||
export const SplitingRegister = window.dependencies;
|
||||
|
|
|
@ -1,4 +1,2 @@
|
|||
export * from './module';
|
||||
export * from './customer/routes';
|
||||
|
||||
export {NAME as CUSTOMER_INDEX, COMPONENT as CUSTOMER_INDEX_COMPONENT} from './customer/index'
|
|
@ -1,7 +1,7 @@
|
|||
import template from './index.html';
|
||||
import {module} from '../../module';
|
||||
|
||||
export const NAME = 'customerAdd';
|
||||
export const NAME = 'customerIndex';
|
||||
export const COMPONENT = {
|
||||
template: template,
|
||||
controller: function() {
|
||||
|
|
|
@ -1,31 +0,0 @@
|
|||
import * as core from '@salix/core';
|
||||
import * as index from './index';
|
||||
|
||||
core.module.config(function($stateProvider, $urlRouterProvider) {
|
||||
|
||||
$urlRouterProvider.otherwise("/");
|
||||
|
||||
$stateProvider
|
||||
.state('index', {
|
||||
url: "/index",
|
||||
component: index.CUSTOMER_INDEX,
|
||||
resolve:{
|
||||
load:function(){
|
||||
console.log('hello');
|
||||
}
|
||||
}
|
||||
})
|
||||
.state('add', {
|
||||
url: "/add",
|
||||
template: "<div>add</div>"
|
||||
})
|
||||
.state('edit', {
|
||||
url: "/edit",
|
||||
template: "<div>edit</div>"
|
||||
})
|
||||
.state('delete', {
|
||||
url: "/delete",
|
||||
template: "<div>delete</div>"
|
||||
})
|
||||
|
||||
});
|
|
@ -1,8 +0,0 @@
|
|||
|
||||
|
||||
export const crud = (cb) => {
|
||||
require.ensure([], () => {
|
||||
require('@salix/crud');
|
||||
cb();
|
||||
}, "salix.crud");
|
||||
};
|
|
@ -1,27 +0,0 @@
|
|||
0 info it worked if it ends with ok
|
||||
1 verbose cli [ '/usr/local/Cellar/node/6.3.1/bin/node',
|
||||
1 verbose cli '/usr/local/bin/npm',
|
||||
1 verbose cli 'run',
|
||||
1 verbose cli 'dev' ]
|
||||
2 info using npm@3.10.3
|
||||
3 info using node@v6.3.1
|
||||
4 verbose stack Error: missing script: dev
|
||||
4 verbose stack at run (/usr/local/lib/node_modules/npm/lib/run-script.js:151:19)
|
||||
4 verbose stack at /usr/local/lib/node_modules/npm/lib/run-script.js:61:5
|
||||
4 verbose stack at /usr/local/lib/node_modules/npm/node_modules/read-package-json/read-json.js:356:5
|
||||
4 verbose stack at checkBinReferences_ (/usr/local/lib/node_modules/npm/node_modules/read-package-json/read-json.js:320:45)
|
||||
4 verbose stack at final (/usr/local/lib/node_modules/npm/node_modules/read-package-json/read-json.js:354:3)
|
||||
4 verbose stack at then (/usr/local/lib/node_modules/npm/node_modules/read-package-json/read-json.js:124:5)
|
||||
4 verbose stack at /usr/local/lib/node_modules/npm/node_modules/read-package-json/read-json.js:311:12
|
||||
4 verbose stack at /usr/local/lib/node_modules/npm/node_modules/graceful-fs/graceful-fs.js:78:16
|
||||
4 verbose stack at tryToString (fs.js:455:3)
|
||||
4 verbose stack at FSReqWrap.readFileAfterClose [as oncomplete] (fs.js:442:12)
|
||||
5 verbose cwd /Users/nelo/Documents/node/salix
|
||||
6 error Darwin 16.0.0
|
||||
7 error argv "/usr/local/Cellar/node/6.3.1/bin/node" "/usr/local/bin/npm" "run" "dev"
|
||||
8 error node v6.3.1
|
||||
9 error npm v3.10.3
|
||||
10 error missing script: dev
|
||||
11 error If you need help, you may report this error at:
|
||||
11 error <https://github.com/npm/npm/issues>
|
||||
12 verbose exit [ 1, true ]
|
Loading…
Reference in New Issue