-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add README, add build, remove memoizee dep
- Loading branch information
1 parent
e6f1298
commit ebadc4c
Showing
8 changed files
with
258 additions
and
167 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,41 +1,25 @@ | ||
const mergeTrees = require('broccoli-merge-trees'); | ||
const esTranspiler = require('broccoli-babel-transpiler'); | ||
const Rollup = require('broccoli-rollup'); | ||
const resolve = require('rollup-plugin-node-resolve'); | ||
const commonjs = require('rollup-plugin-commonjs'); | ||
const Rollup = require('broccoli-rollup'); | ||
const rollupConfig = require('./rollup.config.js'); | ||
|
||
let es = 'src'; | ||
es = esTranspiler(es, { | ||
filterExtensions: ['js'], | ||
presets: [ | ||
[ | ||
'@babel/preset-env', | ||
{ | ||
modules: false, | ||
}, | ||
], | ||
], | ||
plugins: ['@babel/plugin-external-helpers'], | ||
}); | ||
|
||
module.exports = es; | ||
|
||
let bundled = new Rollup(es, { | ||
let bundledModule = new Rollup(es, { | ||
rollup: { | ||
...rollupConfig, | ||
input: 'index.js', | ||
output: { | ||
file: 'sequins.js', | ||
format: 'es', | ||
...rollupConfig.output, | ||
file: 'sequins.mjs', | ||
}, | ||
plugins: [ | ||
resolve({ | ||
extensions: ['.mjs', '.js', '.json'], | ||
}), | ||
|
||
commonjs({ | ||
include: ['node_modules/memoizee', 'node_modules/invariant'], | ||
}), | ||
], | ||
}, | ||
}); | ||
|
||
// module.exports = bundled; | ||
let bundledCJS = esTranspiler(bundledModule, { | ||
filterExtensions: ['mjs'], | ||
plugins: [['@babel/plugin-transform-modules-commonjs', { loose: true, strict: true }]], | ||
}); | ||
|
||
module.exports = mergeTrees([bundledModule, bundledCJS, 'compat']); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
# Sequins | ||
|
||
Sequins provides a core mutable data structures for javascript using the rich and proven API developed by [Immutable.js](http://facebook.github.io/immutable-js/) (with [a few tweaks](#differences-from-immutable)). | ||
|
||
## Install | ||
|
||
``` | ||
npm install --save sequins | ||
``` | ||
|
||
OR | ||
|
||
``` | ||
yarn add sequins | ||
``` | ||
|
||
Sequins does not yet support being included outside of a module system. | ||
|
||
## Status | ||
|
||
This project is in alpha. It is not ready for production usage and should be expected to contain (many) omissions and bugs. | ||
|
||
## API Documentation | ||
|
||
This does not exist yet. Want to help me build it? For now you can look at [the immutable docs](http://facebook.github.io/immutable-js/docs/#/) and Sequins' [differences from immutable](#differences-from-immutable). Undocumented parity failures should be considered bugs. | ||
|
||
## Why Sequins? A.K.A. A Brief History of (javascript) Time | ||
|
||
In the beginning, there were turtles all the way down. Wait, no. There were Objects. Objects sucked for storing data, because they could only use string keys, it was possible to have collisions between data and prototype methods, and fixing that problem forced you to give up the entire prototype. It took O(n) time to know the amount data stored in one. It was not suitable for them to implement the Iterable protocol. | ||
|
||
And so ES6 added the `Map` and `Set` core data types to javascript, fixing all these problems in one go. These structures also make it possible, easy even, to reflectively differentiate between data, classes, and class instances. Great! The only downside is that they lack the kind of toolbox that javascript programmers have become quite used to having with Arrays. | ||
|
||
Enter: Sequins. Sequins, by way of the Immutable.js API, offers the benefits of `Map` and `Set` along with the most important common functionality which programmers expect | ||
|
||
- **Sorting**: Sequins includes the `stable` npm module for doing stable sorts. | ||
- **Functional programming**: Sequins includes a full suite of functional programming methods, including of course the common ones: `map`, `filter`, and `reduce`. | ||
- **Type coercion**: Sequins makes it super easy to convert between its data types! | ||
- **Work with objects, if you need!**: `Seq({foo: 1}).map(x => ++x).toObject() // {foo: 2}` | ||
- **group, flatten**: When you need them, do you really want to dig out lodash? Bonus: `reverse`! | ||
|
||
## Differences from Immutable | ||
|
||
- **Unordered types**: All sequins types are ordered because the native data structures which underly them preserve ordering without additional work. | ||
|
||
- **No getIn/setIn/updateIn**: These helpers existed to work around immutability for easily updating deep inside nested structures. Sequins does not have this need. | ||
|
||
- **Sequence get**: In immutable you can still use get on sequences. In Sequins, you cannot. | ||
|
||
- **Eager operations on sequences**: In immmutable, Sequences are lazy, except when certain operations like `sort` or `groupBy` are performed, which immediately evaluate the sequence and cache all the data. These operations in Sequins are still forced to cache data, but they don't force evaluation of the sequence, and the cache must be rebuilt each time the sequence is evaluated. | ||
|
||
- **Sequence locking**: Sequences in Sequins are mutable, like Sequins data structures, meaning the transforms on them generally return the same sequence object to be used for further chaining. Sequence transforms which return a sequence of a different type, however, obviously cannot return the same object. In order to avoid confusion, these operations "lock" the former sequence to further transformation. This ensures that any operations designed to derive multiple sequences from a single base sequence must be explicit. | ||
|
||
- **delete**: In Sequins, the delete operation does not return the collection. It follows the es6 spec, which indicates that the method should return whether or not the key whose deletion was requested existed. | ||
|
||
- **Sequence transforms**: In immutable, transform callbacks generally receive three arguments. `map`, for example, receives `(value, key, collection)`. In Sequins, the `collection` argument is omitted if the transform is done on a sequence. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
module.exports = { | ||
presets: [ | ||
[ | ||
'@babel/preset-env', | ||
{ | ||
modules: false, | ||
}, | ||
], | ||
], | ||
plugins: [ | ||
[ | ||
'@babel/plugin-transform-runtime', | ||
{ | ||
useESModules: true, | ||
}, | ||
], | ||
], | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
// TODO remove me when babel-plugin-add-module-exports works right | ||
module.exports = require('./sequins').default; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,58 +1,69 @@ | ||
{ | ||
"name": "sequins", | ||
"version": "0.0.1", | ||
"main": "lib/index", | ||
"description": "Mutable sequences and native data structures (Map, Set, List) following the Immutable.js API", | ||
"author": "[email protected]", | ||
"license": "MIT", | ||
"files": [ | ||
"dist/**" | ||
], | ||
"main": "dist/_sequins.js", | ||
"module": "dist/sequins.mjs", | ||
"scripts": { | ||
"build": "broccoli build dist --overwrite", | ||
"test": "jest" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "git+https://github.com/conartist6/sequins.git" | ||
}, | ||
"keywords": [ | ||
"iterator", | ||
"generator", | ||
"mutable", | ||
"sequence", | ||
"seq", | ||
"iter-tools", | ||
"es6", | ||
"es2015" | ||
], | ||
"author": "[email protected]", | ||
"license": "MIT", | ||
"bugs": { | ||
"url": "https://github.com/conartist6/sequins/issues" | ||
}, | ||
"files": "lib", | ||
"homepage": "https://github.com/conartist6/sequins#readme", | ||
"devDependencies": { | ||
"@babel/core": "^7.0.0-beta.56", | ||
"@babel/plugin-external-helpers": "^7.0.0-rc.3", | ||
"@babel/plugin-transform-classes": "^7.0.0-beta.56", | ||
"@babel/plugin-transform-modules-commonjs": "^7.0.0-beta.56", | ||
"@babel/plugin-transform-modules-commonjs": "^7.0.0", | ||
"@babel/plugin-transform-runtime": "^7.0.0", | ||
"@babel/preset-env": "7.0.0-beta.56", | ||
"babel-core": "^7.0.0-beta.41", | ||
"babel-jest": "^23.4.2", | ||
"broccoli": "^2.0.0-beta.4", | ||
"broccoli-babel-transpiler": "7.0.0-beta.4", | ||
"broccoli-cli": "^1.0.0", | ||
"broccoli-merge-trees": "^3.0.1", | ||
"broccoli-rollup": "^2.1.1", | ||
"jest": "^23.4.2", | ||
"rollup-plugin-babel": "^4.0.0-beta.8", | ||
"rollup-plugin-babel": "^4.0.2", | ||
"rollup-plugin-commonjs": "^9.1.6", | ||
"rollup-plugin-node-resolve": "^3.3.0" | ||
}, | ||
"dependencies": { | ||
"@babel/runtime": "^7.0.0", | ||
"invariant": "^2.2.4", | ||
"iter-tools": "^6.0.0", | ||
"memoizee": "^0.4.12", | ||
"stable": "^0.1.8" | ||
}, | ||
"jest": { | ||
"moduleFileExtensions": [ | ||
"js" | ||
], | ||
"setupTestFrameworkScriptFile": "<rootDir>/jest_setup.js" | ||
} | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "git+https://github.com/conartist6/sequins.git" | ||
}, | ||
"keywords": [ | ||
"mutable", | ||
"immutable", | ||
"map", | ||
"set", | ||
"list", | ||
"stable", | ||
"sort", | ||
"sequence", | ||
"seq", | ||
"iter-tools", | ||
"es6", | ||
"es2015" | ||
], | ||
"bugs": { | ||
"url": "https://github.com/conartist6/sequins/issues" | ||
}, | ||
"homepage": "https://github.com/conartist6/sequins#readme" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
const resolve = require('rollup-plugin-node-resolve'); | ||
const babel = require('rollup-plugin-babel'); | ||
const commonjs = require('rollup-plugin-commonjs'); | ||
|
||
module.exports = { | ||
input: 'src/index.js', | ||
output: { | ||
file: 'dist/sequins.mjs', | ||
format: 'es', | ||
}, | ||
external: ['iter-tools', 'invariant', 'stable', '@babel/runtime/regenerator'], | ||
plugins: [ | ||
resolve({ | ||
extensions: ['.mjs', '.js', '.json'], | ||
}), | ||
babel({ | ||
exclude: 'node_modules/**', | ||
runtimeHelpers: true, | ||
}), | ||
commonjs({ | ||
include: 'node_modules/**', | ||
}), | ||
], | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,15 @@ | ||
import memoize from 'memoizee'; | ||
function makeKey(collectionSubtype, collectionType) { | ||
return `${collectionSubtype}__${collectionType}`; | ||
} | ||
|
||
export function memoizeFactory(factory) { | ||
//const normalizeFn = factory.length > 0 ? collectionType => collectionType : () => null; | ||
//return memoize(factory, normalizeFn); | ||
return memoize(factory); | ||
const results = Object.create(null); | ||
|
||
return function memoizedFactory(Collection, ...dynamicArgs) { | ||
const key = makeKey(...dynamicArgs); | ||
if (!results[key]) { | ||
results[key] = factory(Collection, ...dynamicArgs); | ||
} | ||
return results[key]; | ||
}; | ||
} |
Oops, something went wrong.