Coder Social home page Coder Social logo

scrat.js's Introduction

Scrat.js

介绍

Scrat.js 是与 Scrat 配套使用的前端模块管理框架,Scrat 通过 release 环节将计算出的模块列表、别名、依赖关系、配置等信息传递给 Scrat.js,由 Scrat.js 负责运行时的模块加载、合并请求、缓存等工作。

主要 API 说明

require.async(modules, callback)

说明:加载并运行一组 JS 模块

  • @param {string|array} modules - 要加载并运行的模块列表
  • @param {function} callback - 全部模块及其依赖加载成功后的回调函数

示例:

require.async(['ajax', 'event'], function (ajax, event) {
    ajax.get('/someObjs', {length: 10}, function (data) {
        event.emit('done', data);
    });
});

require.config(options)

说明:设置并返回 Scrat.js 选项

  • @param {object} [options] - 配置选项
  • @returns {object} options

示例:

require.config(__FRAMEWORK_CONFIG__); // Scrat 在编译过程中会自动替换 __FRAMEWORK_CONFIG__ 为配置数据
require.config({
    cache: true, // 开启 localStorage 缓存
    urlPattern: '/path/to/resources/%s', // 资源加载路径
    comboPattern: '/path/to/combo-service??%s' // Combo 服务路径
});

define(id, factory)

说明:定义一个 JS 模块

  • @param {string} id - 模块 id
  • @param {function} factory - 模块的工厂函数

示例:

define('hello', function (require, exports, module) {
    module.exports = function (name) {
        alert('Hello ' + name);
    };
});

scrat.js's People

Contributors

hinc avatar

Watchers

James Cloos avatar mansonchor.github.com avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.