Giter Club home page Giter Club logo

neuron.js's Introduction

Build Status

Neuron

First of all, neuron is not designed for human developers to use directly. Most usually, it works together with neuron-cli.

Neuron is a full feature CommonJS module loader which makes your node-style modules run in browsers.

  • Dynamic resource loading with "module -> resource url" mapping.
  • Implements commonjs Module/1.0 standard.
  • Fully supports SemVer and SemVer ranges: '^a.b.c', '~a.b.c', '>=a.b.c', etc.
  • Implements File Modules of node.js (Maybe the only module loader which could do that.)
  • Supports cyclic dependencies.
  • Implements require.resolve(), __filename, and __dirname for browsers which is similar to node.js.
  • Completely isolated sandboxes.
  • Supports scoped packages

With Neuron, we write web modules exactly the same as we work with node.js, with no Module/Wrappings, no *MD, etc.

Neuron is designed to run in the background without your concern, UNLIKE RequireJS and many other loaders.


Neuron Loader for Browsers

Frequent configurations, for more, just see Configuration section.

<script src="/dist/neuron.js"></script>
<script>
facade('hello', {
  name: 'John'
});
</script>

Install and build dist

npm install
node node/build

With ecma5 compatibility

npm install
node node/build ecma5

facade()

facade(identifier);
facade(identifier, data);
  • identifier String module name with version, seperated with '@'. For example: '[email protected]'

  • data Object will be passed as the parameter of the module.exports.

Method facade loads a module. If the module.exports is a function, facade method will run the function with data as its only parameter.

We call this kind of modules as facade modules which is much like the bins of nodejs.

require(id)

  • id String module identifier.

To require modules. See CommonJS Module/1.0

require.async(id, callback)

  • id String module identifier.
  • callback function(exports) callback must be passed, or require.async will do nothing.

Asynchronously loads a module by id, and then passes the module exports to callback.

You should always pass the callback parameter because neuron can not make sure the exact time when a module is loaded asynchronously.

It is NOT a good practice if the logic of your code relies on the result of the require.async()d module without a callback.

require.resolve(path)

  • path String the relative path to be resolved according to the current module.

Returns the resolved absolute path of the resource.

Returns undefined if path is not a relative path.

Returns undefined if path is even outside the current package.


Developer Guide

Neuron CORE supplies no high-level APIs, which means that neuron core only cares about module dependencies and module wrapping while will do nothing about things such as fetching modules from remote server and injecting them into the current document, and never cares about where a specific module should come from.

Configuration

neuron.config(settings);

settings.resolve function(id)

Method to resolve the module id into url paths.

By default, it works with settings.path, and resolves the module id into

settings.path
+ id
  // '@facebook/[email protected]/react.js' -> 'facebook/[email protected]/react.js'
  .replace(/^@/, '')
  // 'facebook/[email protected]/react.js'
  // -> 'facebook/react/1.0.0/react.js'
  // -> '/mod/facebook/[email protected]/react.js'
  .replace('@', '/');

settings.path String

CommonJS module path, like NODE_PATH, default to '/mod/'.

Pay attension that path will not be resolved to absolute url. So if you don't want a relative path, don't forget 'http://'.

Actually, settings.path only works with settings.resolve and provides a simple way to customize the base path of the package resources. If you defines your own settings.resolve, settings.path will be useless.

settings.loaded String|Array.<id>

To tell neuron loader that those modules are already loaded, and prevent duplicate loading.

If String, we can separate different ids with '|' (comma).

neuron.config({
	loaded: ['[email protected]', '[email protected]']
});

settings.graph Object

The directed graph of all dependencies, which could be parsed by neuron-graph.

The arithmetics to generate the graph is complicated and hard to describe, see https://github.com/kaelzhang/neuron/blob/master/doc/graph.md for details (Too Long; Don't Read)

define()

You should NEVER write this method by hands.

ALWAYS use builders(such as neuron-builder) to generate this method.

define(identifier, dependencies, factory, options);

id (full module id)

Format: <package-name>@<version>/<path-with-extension>

Type: string

The real pathname relative to the root directory of the package.

dependencies

Array.<id>

factory

function(require, exports, module, __filename, __dirname){}

options

options.main

Type Boolean

whether the module is the main entry, i.e. the package.main field in package.json

options.map

Type Object

<id>:<full-module-id>.

require('./a')
require('./lib')
// ->
// map: {
//   './a': '[email protected]/a.js'
//   // require a directory
//   './lib': '[email protected]/lib/index.js'
// }

NPM module: neuron.js

A package to get the JavaScript file of neuron.

var neuron = require('neuron.js');
neuron.version(); // 10.1.0
neuron.content(function(err, content){
  content; // The file content of neuron.js
});

neuron.version();

Returns String the version of neuron for browsers, not the version of npm module neuronjs

neuron.write(dest, callback)

  • dest path
  • callback function(err)

Writes the content of neuron.js to the dest

neuron.content(callback)

  • callback function(err, content)
  • content Buffer the buffer of the content of neuron.js

Gets the content of neuron.js

Related Projects

neuron.js's People

Contributors

love11zi avatar mylyban avatar spricity avatar supersheep avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

neuron.js's Issues

Neuron configurations

  1. to disable combo
  2. to enable module override
  3. force loader to load module by itself
  4. server
  5. path
#neuron/server=localhost:8765,path=mod,ns=NR

Neuron 2.1

  1. Configuration Enhancement
  2. better for debugging

Fx 相关文档 Review

fx/core.md:

  1. fx/core 目前是一个抽象类,不建议任何形式的初始化,请文档中也说明这一点
  2. 移除现有代码示例
  3. 可以在文档中描述,这是所有 fx 相关组件的公有方法

fx/tween.md

  1. fx/tween: Constructor -> Tween: Constructor, fx/morph 同理

fx/easing.md

  1. 请稍微说明 Easing 对象是如何获取的,可以使用

    var Easing = require('fx/easing');

其他说明

  1. 可以直接在 master 分支中进行。
  2. 请按照 SAMPLE.md 中的格式,调整所有文档中的有关参数描述的书写格式

Automate Upgrade Script

Transformers:

  • nr: manage naming of variables
  • exports: convert specified return as module.exports
  • dom: upgrade dom api
  • remove-wrapper: remove NR.define wrapper
  • domevent: upgrade domevent api

Automate Script

automate script to upgrade all modules within a business repo

Reverse Proxy

for online pre-testing

关于events及attrs

ajax现在无法入手了,主要卡在Implements:"events attrs"
我看到现在events放到了NR上面,那attrs现在打算放到哪里?
我的建议是放出来独立的模块,然后可以通过lang再mix回去

另外,按照原来的做法这样写之后

Class.EXTS = {
events:require("neuro-events"),
attrs:require("neuro-attrs")
}

测试用例会抛个错:

mod.p.forEach(function(c){ ...

-- Uncaught TypeError: Cannot call method 'forEach' of undefined

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.