layer

WebJar for layer

Лицензия

Лицензия

MIT
Группа

Группа

org.webjars.npm
Идентификатор

Идентификатор

layer
Последняя версия

Последняя версия

0.1.0
Дата

Дата

Тип

Тип

jar
Описание

Описание

layer
WebJar for layer
Ссылка на сайт

Ссылка на сайт

http://webjars.org
Система контроля версий

Система контроля версий

https://github.com/hnry/layer

Скачать layer

Имя Файла Размер
layer-0.1.0.pom
layer-0.1.0.jar 12 KB
layer-0.1.0-sources.jar 22 bytes
layer-0.1.0-javadoc.jar 22 bytes
Обзор

Как подключить последнюю версию

<!-- https://jarcasting.com/artifacts/org.webjars.npm/layer/ -->
<dependency>
    <groupId>org.webjars.npm</groupId>
    <artifactId>layer</artifactId>
    <version>0.1.0</version>
</dependency>
// https://jarcasting.com/artifacts/org.webjars.npm/layer/
implementation 'org.webjars.npm:layer:0.1.0'
// https://jarcasting.com/artifacts/org.webjars.npm/layer/
implementation ("org.webjars.npm:layer:0.1.0")
'org.webjars.npm:layer:jar:0.1.0'
<dependency org="org.webjars.npm" name="layer" rev="0.1.0">
  <artifact name="layer" type="jar" />
</dependency>
@Grapes(
@Grab(group='org.webjars.npm', module='layer', version='0.1.0')
)
libraryDependencies += "org.webjars.npm" % "layer" % "0.1.0"
[org.webjars.npm/layer "0.1.0"]

Зависимости

Библиотека не имеет зависимостей. Это самодостаточное приложение, которое не зависит ни от каких других библиотек.

Модули Проекта

Данный проект не имеет модулей.

Build Status

layer

Unobtrusive transparent proxies with very little setup. Doesn't require re-writing existing code. You can just drop it right in!

Runs anywhere there's javascript (browser & node).

--> (layer) --> (function/object)

// add a simple proxy without modifying any existing code!
var addBig = function(x, y, next) { 
  x = x * 100;
  y = y * 100;
  next(x, y);
}

var that = this;
layer.set(that, add, addBig);

// existing code...
function add(x, y) {
  return x + y;
}

add(2, 2); // 400

And that's it, all instances of calling add() in your existing code now go through addBig() then add()

You don't re-write your code! Or have to call addBig() directly.

(Note: this won't work in node.js because add is private, see here.)

For some fun stuff you can do with layer, check out intercept.js.

Usage / API

Setting a proxy

layer.set(context, function to proxy, proxy function)

Context being scope or this, read more about it here.

In the browser when you set 'null' as the context, it'll default to global (browser only).

Unsetting a proxy

layer.unset(func) or following the example: layer.unset(add)

Skipping your proxy

For those times when you want turn skip a layer...

func.skip() or following out add example add.skip(2, 2)

Replacing not proxying (monkey patching)

layer.replace(context, function to replace, new function)

Stopping a proxy early

At anytime you may stop early by not calling next.

And either call your callback (async) or return (sync);

Install

  • node: npm install layer

  • browser: use layer.min.js

Some advice on knowing the context.

(You can't proxy private variables!)

Because they're private. Not a big deal, and it's obvious enough. But keep in mind that in a node.js, the root of the module all your var's are effectively private (so the readme example above will not work).

Work around would be exports.add and the context being 'exports' would work. Or if add was in an object var obj = { add: ... }, context being 'obj'.

(Basically, it works like normal except for private variables.)

Some more examples:

var somelib = require('somelib'); 
layer.set(somelib, somelib.func, proxyFn)
function Cat() {}
Cat.prototype.meow = function() {...}

layer.set(Cat.prototype, Cat.prototype.meow, proxyFn)

Версии библиотеки

Версия
0.1.0