basic-signals
Advanced tools
Comparing version 0.1.0 to 0.1.1
@@ -1,3 +0,5 @@ | ||
var Signal = { | ||
import { fromIncomplete } from 'static-land'; | ||
var Signal = fromIncomplete({ | ||
// creates an arbitrary signal | ||
@@ -82,3 +84,3 @@ | ||
}, signal); | ||
}); | ||
}, null); | ||
}, | ||
@@ -93,3 +95,3 @@ ap: function ap(ofFn, ofValue) { | ||
ofValue.observe(update); | ||
}); | ||
}, null); | ||
}, | ||
@@ -103,6 +105,6 @@ scan: function scan(reducer, seed, signal) { | ||
}, signal); | ||
}); | ||
}, null); | ||
} | ||
}; | ||
}); | ||
export default Signal; |
@@ -1,2 +0,2 @@ | ||
"use strict"; | ||
'use strict'; | ||
@@ -6,4 +6,7 @@ Object.defineProperty(exports, "__esModule", { | ||
}); | ||
var Signal = { | ||
var _staticLand = require('static-land'); | ||
var Signal = (0, _staticLand.fromIncomplete)({ | ||
// creates an arbitrary signal | ||
@@ -88,3 +91,3 @@ | ||
}, signal); | ||
}); | ||
}, null); | ||
}, | ||
@@ -99,3 +102,3 @@ ap: function ap(ofFn, ofValue) { | ||
ofValue.observe(update); | ||
}); | ||
}, null); | ||
}, | ||
@@ -109,6 +112,6 @@ scan: function scan(reducer, seed, signal) { | ||
}, signal); | ||
}); | ||
}, null); | ||
} | ||
}; | ||
}); | ||
exports.default = Signal; |
{ | ||
"version": "0.1.0", | ||
"version": "0.1.1", | ||
"description": "Experimental very basic reactive signals for JavaScript", | ||
@@ -11,14 +11,4 @@ "main": "lib/index.js", | ||
"scripts": { | ||
"es": "BABEL_ENV=rollup babel src --out-dir lib-es", | ||
"commonjs": "BABEL_ENV=commonjs babel src --out-dir lib", | ||
"umd": "BABEL_ENV=rollup rollup -c", | ||
"umd-min": "uglifyjs -m -c -- umd/basicSignals.js > umd/basicSignals.min.js", | ||
"build": "rm -rf lib lib-es umd && npm run es && npm run commonjs && npm run umd && npm run umd-min", | ||
"coverage": "BABEL_ENV=commonjs nyc tape test/*.js && nyc report --reporter=text-lcov > lcov.info", | ||
"coveralls": "BABEL_ENV=commonjs nyc tape test/*.js && nyc report --reporter=text-lcov | coveralls", | ||
"tapec": "nodemon --watch test --watch src --exec \"BABEL_ENV=commonjs tape -r babel-register test/*.js | tap-notify | faucet\"", | ||
"test": "eslint . && BABEL_ENV=commonjs tape -r babel-register test/*.js | faucet", | ||
"preversion": "npm run test && npm run build", | ||
"postversion": "git push && git push origin --tags && npm publish", | ||
"repl": "BABEL_ENV=commonjs node --require babel-register" | ||
"lobot": "lobot", | ||
"test": "eslint . && lobot test" | ||
}, | ||
@@ -29,30 +19,12 @@ "keywords": [], | ||
"devDependencies": { | ||
"babel-cli": "6.6.5", | ||
"babel-core": "6.7.4", | ||
"babel-eslint": "6.0.0", | ||
"babel-plugin-transform-es2015-modules-commonjs": "6.7.4", | ||
"babel-plugin-transform-object-rest-spread": "6.6.5", | ||
"babel-preset-es2015": "6.6.0", | ||
"babel-preset-es2015-rollup": "1.1.1", | ||
"babel-register": "6.7.2", | ||
"coveralls": "2.11.9", | ||
"eslint": "2.5.1", | ||
"fantasy-check": "0.3.2", | ||
"babel-eslint": "6.0.2", | ||
"eslint": "2.6.0", | ||
"fantasy-land": "0.2.1", | ||
"faucet": "0.0.1", | ||
"nodemon": "1.9.1", | ||
"nyc": "6.1.1", | ||
"rollup": "0.25.6", | ||
"rollup-plugin-babel": "2.4.0", | ||
"rollup-plugin-commonjs": "2.2.1", | ||
"rollup-plugin-node-resolve": "1.5.0", | ||
"tap-notify": "1.0.0", | ||
"tape": "4.5.1", | ||
"tape-catch": "1.0.4", | ||
"transducers-js": "0.4.174", | ||
"uglify-js": "2.6.2" | ||
"lobot": "0.1.8", | ||
"static-land": "0.1.3" | ||
}, | ||
"dependencies": {}, | ||
"peerDependencies": { | ||
"fantasy-land": ">=0.2.0" | ||
"fantasy-land": ">=0.2.0", | ||
"static-land": "0.1.3" | ||
}, | ||
@@ -67,32 +39,3 @@ "name": "basic-signals", | ||
}, | ||
"homepage": "https://github.com/rpominov/basic-signals#readme", | ||
"babel": { | ||
"env": { | ||
"rollup": { | ||
"presets": [ | ||
"babel-preset-es2015-rollup" | ||
], | ||
"plugins": [ | ||
"transform-object-rest-spread" | ||
] | ||
}, | ||
"commonjs": { | ||
"presets": [ | ||
"babel-preset-es2015" | ||
], | ||
"plugins": [ | ||
"transform-object-rest-spread" | ||
] | ||
} | ||
} | ||
}, | ||
"nyc": { | ||
"require": [ | ||
"babel-register" | ||
], | ||
"all": true, | ||
"include": [ | ||
"**/src/**" | ||
] | ||
} | ||
"homepage": "https://github.com/rpominov/basic-signals#readme" | ||
} |
@@ -45,1 +45,10 @@ # Basic-signals | ||
``` | ||
## Development | ||
``` | ||
npm run lobot -- --help | ||
``` | ||
Run [lobot](https://github.com/rpominov/lobot) commands as `npm run lobot -- args...` |
@@ -7,4 +7,305 @@ (function (global, factory) { | ||
var Signal = { | ||
function __commonjs(fn, module) { return module = { exports: {} }, fn(module, module.exports), module.exports; } | ||
function flow(value) { | ||
for (var _len = arguments.length, fns = Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) { | ||
fns[_key - 1] = arguments[_key]; | ||
} | ||
return fns.reduce(function (x, fn) { | ||
return fn(x); | ||
}, value); | ||
} | ||
function _curry(length, received, fn) { | ||
return function () { | ||
for (var _len2 = arguments.length, args = Array(_len2), _key2 = 0; _key2 < _len2; _key2++) { | ||
args[_key2] = arguments[_key2]; | ||
} | ||
var all = received.concat(args); | ||
return all.length >= length ? fn.apply(undefined, babelHelpers.toConsumableArray(all)) : _curry(length, all, fn); | ||
}; | ||
} | ||
function curry(fn) { | ||
if (fn.__fnatasyLandStaticCurried__) { | ||
return fn; | ||
} | ||
var curried = _curry(fn.length, [], fn); | ||
curried.__fnatasyLandStaticCurried__ = true; | ||
return curried; | ||
} | ||
var mapObj = curry(function (fn, obj) { | ||
var result = {}; | ||
Object.keys(obj).forEach(function (key) { | ||
result[key] = fn(obj[key]); | ||
}); | ||
return result; | ||
}); | ||
var curryAll = mapObj(curry); | ||
var map2 = curry(function (T, fn, t1, t2) { | ||
return T.ap(T.map(curry(fn), t1), t2); | ||
}); | ||
var map3 = curry(function (T, fn, t1, t2, t3) { | ||
return T.ap(T.ap(T.map(curry(fn), t1), t2), t3); | ||
}); | ||
var ap = curry(function (T, tf, tx) { | ||
return T.chain(function (f) { | ||
return T.map(f, tx); | ||
}, tf); | ||
}); | ||
var reduce = curry(function (T, fn, seed, tx) { | ||
return T.toArray(tx).reduce(fn, seed); | ||
}); | ||
var toArray = curry(function (T, tx) { | ||
return T.reduce(function (r, i) { | ||
return r.concat([i]); | ||
}, [], tx); | ||
}); | ||
var mapViaApplicative = curry(function (T, fn, tx) { | ||
return T.ap(T.of(fn), tx); | ||
}); | ||
var mapViaMonad = curry(function (T, fn, tx) { | ||
return T.chain(function (x) { | ||
return T.of(fn(x)); | ||
}, tx); | ||
}); | ||
var traverse = curry(function (T, Inner, fn, tx) { | ||
return T.sequence(Inner, T.map(fn, tx)); | ||
}); | ||
var join = curry(function (T, tt) { | ||
return T.chain(function (t) { | ||
return t; | ||
}, tt); | ||
}); | ||
var chain = curry(function (T, fn, tx) { | ||
return T.join(T.map(fn, tx)); | ||
}); | ||
var deriveAll = function deriveAll(T) { | ||
var added = {}; | ||
if (T.join === undefined && T.chain) { | ||
added.join = join(T); | ||
} | ||
if (T.chain === undefined && T.join) { | ||
added.chain = chain(T); | ||
} | ||
if (T.map === undefined && T.of && T.chain) { | ||
added.map = mapViaMonad(T); | ||
} | ||
if (T.ap === undefined && T.map && T.chain) { | ||
added.ap = ap(T); | ||
} | ||
if (T.map2 === undefined && T.ap && T.map) { | ||
added.map2 = map2(T); | ||
} | ||
if (T.map3 === undefined && T.ap && T.map) { | ||
added.map3 = map3(T); | ||
} | ||
if (T.map === undefined && T.of && T.ap) { | ||
added.map = mapViaApplicative(T); | ||
} | ||
if (T.reduce === undefined && T.toArray) { | ||
added.reduce = reduce(T); | ||
} | ||
if (T.toArray === undefined && T.reduce) { | ||
added.toArray = toArray(T); | ||
} | ||
if (T.traverse === undefined && T.map && T.sequence) { | ||
added.traverse = traverse(T); | ||
} | ||
return babelHelpers.extends({}, T, added); | ||
}; | ||
var index = __commonjs(function (module) { | ||
module.exports = { | ||
equals: 'equals', | ||
concat: 'concat', | ||
empty: 'empty', | ||
map: 'map', | ||
ap: 'ap', | ||
of: 'of', | ||
reduce: 'reduce', | ||
sequence: 'sequence', | ||
chain: 'chain', | ||
extend: 'extend', | ||
extract: 'extract' | ||
} | ||
}); | ||
function fromIncomplete(T) { | ||
return curryAll(deriveAll(T)); | ||
} | ||
var Arr = fromIncomplete({ | ||
equals: function equals(a, b) { | ||
if (a.length !== b.length) { | ||
return false; | ||
} | ||
for (var i = 0; i < a.length; i++) { | ||
if (a[i] !== b[i]) { | ||
return false; | ||
} | ||
} | ||
return true; | ||
}, | ||
of: function of(x) { | ||
return [x]; | ||
}, | ||
empty: function empty() { | ||
return []; | ||
}, | ||
concat: function concat(a, b) { | ||
return a.concat(b); | ||
}, | ||
map: function map(fn, arr) { | ||
return arr.map(function (x) { | ||
return fn(x); | ||
}); | ||
}, | ||
sequence: function sequence(T, arr) { | ||
return arr.reduce(T.map2(function (r, i) { | ||
return r.concat([i]); | ||
}), T.of([])); | ||
}, | ||
toArray: function toArray(arr) { | ||
return arr; | ||
}, | ||
chain: function chain(fn, arr) { | ||
return Arr.reduce(Arr.concat, Arr.empty(), arr.map(fn)); | ||
} | ||
}); | ||
var Id = fromIncomplete({ | ||
equals: function equals(idA, idB) { | ||
return idA === idB; | ||
}, | ||
of: function of(x) { | ||
return x; | ||
}, | ||
map: function map(fn, idX) { | ||
return fn(idX); | ||
}, | ||
reduce: function reduce(fn, seed, idX) { | ||
return fn(seed, idX); | ||
}, | ||
chain: function chain(fn, idX) { | ||
return fn(idX); | ||
}, | ||
sequence: function sequence(T, idT) { | ||
return idT; | ||
}, | ||
extract: function extract(idX) { | ||
return idX; | ||
}, | ||
extend: function extend(fn, idX) { | ||
return Id.of(fn(idX)); | ||
} | ||
}); | ||
var Pair = fromIncomplete({ | ||
map: function map(fn, pairX) { | ||
return Pair.create(fn(pairX.first), pairX.second); | ||
}, | ||
sequence: function sequence(T, pairT) { | ||
return T.map(Pair.createInverse(pairT.second), pairT.first); | ||
}, | ||
create: function create(first, second) { | ||
return { first: first, second: second }; | ||
}, | ||
createInverse: function createInverse(second, first) { | ||
return { first: first, second: second }; | ||
}, | ||
first: function first(pairT) { | ||
return pairT.first; | ||
}, | ||
second: function second(pairT) { | ||
return pairT.second; | ||
} | ||
}); | ||
var Obj = fromIncomplete({ | ||
map: mapObj, | ||
equals: function equals(objA, objB) { | ||
var keysA = Object.keys(objA); | ||
var keysB = Object.keys(objB); | ||
if (keysA.length !== keysB.length) { | ||
return false; | ||
} | ||
for (var i = 0; i < keysA.length; i++) { | ||
var key = keysA[i]; | ||
if (keysB.indexOf(key) === -1) { | ||
return false; | ||
} | ||
if (objA[key] !== objB[key]) { | ||
return false; | ||
} | ||
} | ||
return true; | ||
}, | ||
empty: function empty() { | ||
return {}; | ||
}, | ||
concat: function concat(objA, objB) { | ||
return babelHelpers.extends({}, objA, objB); | ||
}, | ||
toArray: function toArray(objX) { | ||
return Object.keys(objX).map(function (key) { | ||
return objX[key]; | ||
}); | ||
}, | ||
sequence: function sequence(T, objT) { | ||
return flow(objT, Obj.toPairs, Arr.map(Pair.sequence(T)), Arr.sequence(T), T.map(Obj.fromPairs)); | ||
}, | ||
ap: function ap(objF, objX) { | ||
var applyX = function applyX(pair) { | ||
return Pair.map(function (fn) { | ||
return fn(objX[Pair.second(pair)]); | ||
}, pair); | ||
}; | ||
return flow(objF, Obj.toPairs, Arr.map(applyX), Obj.fromPairs); | ||
}, | ||
toPairs: function toPairs(objX) { | ||
return Object.keys(objX).map(function (key) { | ||
return Pair.create(objX[key], key); | ||
}); | ||
}, | ||
fromPairs: function fromPairs(pairs) { | ||
var result = {}; | ||
pairs.forEach(function (pair) { | ||
result[Pair.second(pair)] = Pair.first(pair); | ||
}); | ||
return result; | ||
} | ||
}); | ||
var Signal = fromIncomplete({ | ||
// creates an arbitrary signal | ||
@@ -89,3 +390,3 @@ | ||
}, signal); | ||
}); | ||
}, null); | ||
}, | ||
@@ -100,3 +401,3 @@ ap: function ap(ofFn, ofValue) { | ||
ofValue.observe(update); | ||
}); | ||
}, null); | ||
}, | ||
@@ -110,5 +411,5 @@ scan: function scan(reducer, seed, signal) { | ||
}, signal); | ||
}); | ||
}, null); | ||
} | ||
}; | ||
}); | ||
@@ -115,0 +416,0 @@ return Signal; |
@@ -1,1 +0,1 @@ | ||
!function(n,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):n.BasicSignals=e()}(this,function(){"use strict";var n={create:function(n,e){var t=e,r=[];return n(function(n){t=n,r.forEach(function(n){return n()})}),{get:function(){return t},observe:function(n){var e=!1,t=function(){e||n()};return r=r.concat([t]),function(){e=!0;var n=r.indexOf(t);-1!==n&&(r=r.slice(0,n).concat(r.slice(n+1,r.length)))}}}},react:function(n,e){return n(e.get()),e.observe(function(){n(e.get())})},of:function(n){return{get:function(){return n},observe:function(){}}},map:function(n,e){return{get:function(){return n(e.get())},observe:function(n){return e.observe(n)}}},chain:function(e,t){return n.create(function(r){var c=null;n.react(function(t){c&&c(),c=n.react(r,e(t))},t)})},ap:function(e,t){return n.create(function(n){var r=function(){n(e.get()(t.get()))};r(),e.observe(r),t.observe(r)})},scan:function(e,t,r){return n.create(function(c){var o=t;n.react(function(n){o=e(o,n),c(o)},r)})}};return n}); | ||
!function(n,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):n.BasicSignals=e()}(this,function(){"use strict";function n(n,e){return e={exports:{}},n(e,e.exports),e.exports}function e(n){for(var e=arguments.length,r=Array(e>1?e-1:0),t=1;e>t;t++)r[t-1]=arguments[t];return r.reduce(function(n,e){return e(n)},n)}function r(n,e,t){return function(){for(var u=arguments.length,c=Array(u),o=0;u>o;o++)c[o]=arguments[o];var i=e.concat(c);return i.length>=n?t.apply(void 0,babelHelpers.toConsumableArray(i)):r(n,i,t)}}function t(n){if(n.__fnatasyLandStaticCurried__)return n;var e=r(n.length,[],n);return e.__fnatasyLandStaticCurried__=!0,e}function u(n){return o(y(n))}var c=t(function(n,e){var r={};return Object.keys(e).forEach(function(t){r[t]=n(e[t])}),r}),o=c(t),i=t(function(n,e,r,u){return n.ap(n.map(t(e),r),u)}),a=t(function(n,e,r,u,c){return n.ap(n.ap(n.map(t(e),r),u),c)}),f=t(function(n,e,r){return n.chain(function(e){return n.map(e,r)},e)}),s=t(function(n,e,r,t){return n.toArray(t).reduce(e,r)}),p=t(function(n,e){return n.reduce(function(n,e){return n.concat([e])},[],e)}),d=t(function(n,e,r){return n.ap(n.of(e),r)}),m=t(function(n,e,r){return n.chain(function(r){return n.of(e(r))},r)}),v=t(function(n,e,r,t){return n.sequence(e,n.map(r,t))}),l=t(function(n,e){return n.chain(function(n){return n},e)}),h=t(function(n,e,r){return n.join(n.map(e,r))}),y=function(n){var e={};return void 0===n.join&&n.chain&&(e.join=l(n)),void 0===n.chain&&n.join&&(e.chain=h(n)),void 0===n.map&&n.of&&n.chain&&(e.map=m(n)),void 0===n.ap&&n.map&&n.chain&&(e.ap=f(n)),void 0===n.map2&&n.ap&&n.map&&(e.map2=i(n)),void 0===n.map3&&n.ap&&n.map&&(e.map3=a(n)),void 0===n.map&&n.of&&n.ap&&(e.map=d(n)),void 0===n.reduce&&n.toArray&&(e.reduce=s(n)),void 0===n.toArray&&n.reduce&&(e.toArray=p(n)),void 0===n.traverse&&n.map&&n.sequence&&(e.traverse=v(n)),babelHelpers["extends"]({},n,e)},b=(n(function(n){n.exports={equals:"equals",concat:"concat",empty:"empty",map:"map",ap:"ap",of:"of",reduce:"reduce",sequence:"sequence",chain:"chain",extend:"extend",extract:"extract"}}),u({equals:function(n,e){if(n.length!==e.length)return!1;for(var r=0;r<n.length;r++)if(n[r]!==e[r])return!1;return!0},of:function(n){return[n]},empty:function(){return[]},concat:function(n,e){return n.concat(e)},map:function(n,e){return e.map(function(e){return n(e)})},sequence:function(n,e){return e.reduce(n.map2(function(n,e){return n.concat([e])}),n.of([]))},toArray:function(n){return n},chain:function(n,e){return b.reduce(b.concat,b.empty(),e.map(n))}})),g=u({equals:function(n,e){return n===e},of:function(n){return n},map:function(n,e){return n(e)},reduce:function(n,e,r){return n(e,r)},chain:function(n,e){return n(e)},sequence:function(n,e){return e},extract:function(n){return n},extend:function(n,e){return g.of(n(e))}}),x=u({map:function(n,e){return x.create(n(e.first),e.second)},sequence:function(n,e){return n.map(x.createInverse(e.second),e.first)},create:function(n,e){return{first:n,second:e}},createInverse:function(n,e){return{first:e,second:n}},first:function(n){return n.first},second:function(n){return n.second}}),q=u({map:c,equals:function(n,e){var r=Object.keys(n),t=Object.keys(e);if(r.length!==t.length)return!1;for(var u=0;u<r.length;u++){var c=r[u];if(-1===t.indexOf(c))return!1;if(n[c]!==e[c])return!1}return!0},empty:function(){return{}},concat:function(n,e){return babelHelpers["extends"]({},n,e)},toArray:function(n){return Object.keys(n).map(function(e){return n[e]})},sequence:function(n,r){return e(r,q.toPairs,b.map(x.sequence(n)),b.sequence(n),n.map(q.fromPairs))},ap:function(n,r){var t=function(n){return x.map(function(e){return e(r[x.second(n)])},n)};return e(n,q.toPairs,b.map(t),q.fromPairs)},toPairs:function(n){return Object.keys(n).map(function(e){return x.create(n[e],e)})},fromPairs:function(n){var e={};return n.forEach(function(n){e[x.second(n)]=x.first(n)}),e}}),j=u({create:function(n,e){var r=e,t=[];return n(function(n){r=n,t.forEach(function(n){return n()})}),{get:function(){return r},observe:function(n){var e=!1,r=function(){e||n()};return t=t.concat([r]),function(){e=!0;var n=t.indexOf(r);-1!==n&&(t=t.slice(0,n).concat(t.slice(n+1,t.length)))}}}},react:function(n,e){return n(e.get()),e.observe(function(){n(e.get())})},of:function(n){return{get:function(){return n},observe:function(){}}},map:function(n,e){return{get:function(){return n(e.get())},observe:function(n){return e.observe(n)}}},chain:function(n,e){return j.create(function(r){var t=null;j.react(function(e){t&&t(),t=j.react(r,n(e))},e)},null)},ap:function(n,e){return j.create(function(r){var t=function(){r(n.get()(e.get()))};t(),n.observe(t),e.observe(t)},null)},scan:function(n,e,r){return j.create(function(t){var u=e;j.react(function(e){u=n(u,e),t(u)},r)},null)}});return j}); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
23910
5
569
54
2