calculo de modelos dependientes de manera asíncrona

This commit is contained in:
nelo 2016-10-07 11:45:37 +02:00
parent 4d6ad1a910
commit 8c88988ebf
12 changed files with 91 additions and 116 deletions

View File

@ -35,7 +35,7 @@ export const graphRoutes = {
],
graphDependendies: {
compras:["crud"],
crud:[]
compras: ["crud"],
crud: []
}
};

View File

@ -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);
});

View File

@ -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);

View File

@ -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';

View File

@ -0,0 +1 @@
export * from './spliting';

View File

@ -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);

View File

@ -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;

View File

@ -1,4 +1,2 @@
export * from './module';
export * from './customer/routes';
export {NAME as CUSTOMER_INDEX, COMPONENT as CUSTOMER_INDEX_COMPONENT} from './customer/index'

View File

@ -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() {

View File

@ -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>"
})
});

View File

@ -1,8 +0,0 @@
export const crud = (cb) => {
require.ensure([], () => {
require('@salix/crud');
cb();
}, "salix.crud");
};

View File

@ -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 ]