码迷,mamicode.com
首页 > 其他好文 > 详细

Promise 练习

时间:2019-01-27 21:32:53      阅读:205      评论:0      收藏:0      [点我收藏+]

标签:private   event   proxy   tin   boolean   lov   str   this   star   

import { ModelClass } from "engine/injector/Injector";
import { Inject } from "core/injector/Injector";
import { environment } from "engine/env/Environment";
 
@ModelClass
export class ExerciseProxy {
 
private polyfill_suffix : string = "/s17/lib/polyfill/polyfill.min.js" ;
private vue_suffix : string = "/s17/lib/vue/2.2.5/vue.min.js" ;
private vuex_suffix : string = "/s17/lib/vue/plugin/vuex/2.2.1/vuex.min.js" ;
private venus_js_suffix : string = "/s17/lib/venus/2.5.1/venus.min.js" ;
private venus_css_suffix : string = "/s17/lib/venus/2.5.1/css/venus.min.css" ;
 
private initialized : boolean = false ;
 
public startInitialize( completeCbk: ( ) => void): void
{
if ( this.initialized ) {
setTimeout( function () {
completeCbk( ) ;
}, 0 ) ;
}
let __promise = window["Promise"] ;
let env: string = environment.env ;
let promise = new __promise( ( resolove, reject ) => {
let script = document.createElement("script") ;
script.type = ‘text/javascript‘;
document.head.appendChild( script ) ;
let url = environment.toCDNHostURL(this.polyfill_suffix, false, false) ;
script.onload = function ( evt: Event ): void {
resolove("polyfill success") ;
} ;
script.src = url ;
} ) ;
 
promise.then( (data: string) => {
let promise = new __promise( ( resolove, reject ) => {
let script = document.createElement("script") ;
script.type = ‘text/javascript‘;
document.head.appendChild( script ) ;
let url = environment.toCDNHostURL(this.vue_suffix, false, false) ;
script.onload = function ( evt: Event ): void {
resolove("vue success") ;
} ;
script.src = url ;
} ) ;
 
return promise ;
} ).then( (data: string) => {
let promise = new __promise( ( resolove, reject ) => {
let script = document.createElement("script") ;
script.type = ‘text/javascript‘;
document.head.appendChild( script ) ;
let url = environment.toCDNHostURL(this.vuex_suffix, false, false) ;
script.onload = function ( evt: Event ): void {
resolove("vuex success") ;
} ;
script.src = url ;
} ) ;
 
return promise ;
} ).then( (data: string) => {
let promise = new __promise( ( resolove, reject ) => {
let script = document.createElement("script") ;
script.type = ‘text/javascript‘;
document.head.appendChild( script ) ;
let url = environment.toCDNHostURL(this.venus_js_suffix, false, false) ;
script.onload = function ( evt: Event ): void {
resolove("venus_js success") ;
completeCbk( ) ;
} ;
script.src = url ;
} ) ;
 
return promise ;
} ).then( (data: string) => {
let promise = new __promise( ( resolove, reject ) => {
let link = document.createElement(‘link‘);
link.rel = ‘stylesheet‘;
link.type = ‘text/css‘;
document.head.appendChild( link ) ;
let url = environment.toCDNHostURL(this.venus_css_suffix, false, false) ;
link.onload = function ( evt: Event ): void {
resolove("venus_css success") ;
completeCbk( ) ;
} ;
link.href = url ;
} ) ;
 
return promise ;
} ) ;
}
}
 
 

Promise 练习

标签:private   event   proxy   tin   boolean   lov   str   this   star   

原文地址:https://www.cnblogs.com/jason-beijing/p/10327451.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!