Skip to content
/ In Public
forked from PaulGuo/In

一个轻量级的 JavaScript 颗粒化模块加载和依赖关系管理解决方案

Notifications You must be signed in to change notification settings

Credochen/In

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

68 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

 _____       
|_   _|      
  | |  _ __  
  | | | '_ \ 
 _| |_| | | |
|_____|_| |_|  v0.1.8 build 110428111007

About the author

Guokai,1988-08-08
Beijing - Chaoyang
[Benben Blog](http://benben.cc/)

Overview the In.js

Author: Guokai
Email/Gtalk: [email protected]
Create Datetime: 2011-04-28
Last Update: 2011-10-07
Namespace: window.In
Description: this a light framework that can manage dependency of the modules,
most important,you can load them on-demand,asynchronous and multi-threaded...
License: Apache License,Version 2.0

Usage:


In.add('mod1',{path:'url',type:'js',charset:'utf-8',rely:['mod2','mod3']});
In.use('mod1','mod2','mod3',function() {});
In('mod1','mod2','mod3',function() {}); -> short for In.use()
In.ready('mod1','mod2','mod3',function() {});
In.later(3000,'mod1','mod2','mod3',function() {});
In.css(inline-css);
In.config(name,value);

Release:

Version: 0.1.8
Build: 110428111007

Examples:

1、import In.js to your webpage

例如:底层框架为jQuery 1.5.2-min.js,并引用in时自动加载。

<script type="text/javascript" src="in.js" autoload="true" core="jquery 1.5.2-min.js"></script>

2、In.add()

加载三个待执行的javascript模块,分别为mod1、mod2、mod3,其中mod2依赖于mod3.

<script type="text/javascript">
	In.add('mod1',{path:'mod1.js',type:'js',charset:'utf-8'});
	In.add('mod2',{path:'mod2.js',type:'js',charset:'utf-8',rely:['mod3']});
	In.add('mod3',{path:'mod3.js',type:'js',charset:'utf-8'});
</script>

3、In() or In.use()

旧版本队列内为顺序加载,如需向后兼容,请事先配置In.config('serial',true)更换为默认串行加载,新版本的队列默认为并行执行,队列中最后一个函数被视为回调函数,下面的代码会并行加载mod1,mod2,function,并立即执行,三者均加载完毕后执行回调函数。

<script type="text/javascript">
	//真正的加载顺序为 mod1 || mod2 || function -> function[callback]
	var demo=In('mod1','mod2',function() {
		console.log('我跟mod1和mod2是并行的关系');
	},function() {
		console.log('我是回调函数,他们都加载完毕才会触发我');
	});
</script>

4、In.ready()

domReady之后加载队列

<script type="text/javascript">
	In.ready('mod1','mod2',function() {
		console.log($);
	});
</script>

5、In.later()

延迟加载队列

<script type="text/javascript">
	//延迟3秒加载队列
	In.later(3000,'mod1','mod2',function() {
		console.log($);
	});
</script>

6、In.css()

动态注入CSS

<script type="text/javascript">
	In.css('body {background:yellow}');
</script>

7、In.config()

配置函数

<script type="text/javascript">
	//设置为串行加载模式,兼容旧的写法
	In.config('serial',true);
	//设置核心库,核心库会被所有模块依赖
	In.config('core','jquery 1.5.2-min.js');
</script>

About

一个轻量级的 JavaScript 颗粒化模块加载和依赖关系管理解决方案

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published