Repository: ericelliott/irecord Branch: master Commit: e4a3caaaa2c2 Files: 17 Total size: 26.3 KB Directory structure: gitextract_u_dhe8s4/ ├── .eslintrc ├── .gitignore ├── .travis.yml ├── LICENSE ├── README.md ├── build/ │ ├── index.js │ └── test/ │ ├── basics.js │ ├── index.js │ ├── rx.js │ └── stampit.js ├── package.json ├── reactive-programming.md ├── source/ │ └── index.js └── test/ ├── basics.js ├── index.js ├── rx.js └── stampit.js ================================================ FILE CONTENTS ================================================ ================================================ FILE: .eslintrc ================================================ { "parser": "babel-eslint", "env": { "browser": true, "node": true, "es6": true }, "ecmaFeatures": { "jsx": true, "superInFunctions": false, "classes": false, "modules": [2] }, "rules": { "block-scoped-var": [0], "brace-style": [2, "1tbs", { "allowSingleLine": true }], "camelcase": [0], "comma-dangle": [2, "never"], "comma-spacing": [2], "comma-style": [2, "last"], "complexity": [0, 11], "consistent-return": [2], "consistent-this": [0, "that"], "curly": [2, "multi-line"], "default-case": [2], "dot-notation": [2, { "allowKeywords": true }], "eol-last": [2], "eqeqeq": [2], "func-names": [0], "func-style": [0, "declaration"], "generator-star-spacing": [2, "after"], "global-strict": [2, "always"], "guard-for-in": [0], "handle-callback-err": [0], "key-spacing": [2, { "beforeColon": false, "afterColon": true }], "quotes": [2, "single", "avoid-escape"], "max-depth": [0, 4], "max-len": [0, 80, 4], "max-nested-callbacks": [0, 2], "max-params": [0, 3], "max-statements": [0, 10], "new-parens": [2], "new-cap": [0], "newline-after-var": [0], "no-alert": [2], "no-array-constructor": [2], "no-bitwise": [0], "no-caller": [2], "no-catch-shadow": [2], "no-cond-assign": [2], "no-console": [0], "no-constant-condition": [1], "no-continue": [2], "no-control-regex": [2], "no-debugger": [2], "no-delete-var": [2], "no-div-regex": [0], "no-dupe-args": [2], "no-dupe-keys": [2], "no-duplicate-case": [2], "no-else-return": [0], "no-empty": [2], "no-empty-class": [2], "no-empty-label": [2], "no-eq-null": [0], "no-eval": [2], "no-ex-assign": [2], "no-extend-native": [1], "no-extra-bind": [2], "no-extra-boolean-cast": [2], "no-extra-parens": [0], "no-extra-semi": [1], "no-extra-strict": [2], "no-fallthrough": [2], "no-floating-decimal": [2], "no-func-assign": [2], "no-implied-eval": [2], "no-inline-comments": [0], "no-inner-declarations": [2, "functions"], "no-invalid-regexp": [2], "no-irregular-whitespace": [2], "no-iterator": [2], "no-label-var": [2], "no-labels": [2], "no-lone-blocks": [2], "no-lonely-if": [2], "no-loop-func": [2], "no-mixed-requires": [0, false], "no-mixed-spaces-and-tabs": [2, false], "no-multi-spaces": [2], "no-multi-str": [2], "no-multiple-empty-lines": [2, { "max": 2 }], "no-native-reassign": [1], "no-negated-in-lhs": [2], "no-nested-ternary": [0], "no-new": [2], "no-new-func": [2], "no-new-object": [2], "no-new-require": [0], "no-new-wrappers": [2], "no-obj-calls": [2], "no-octal": [2], "no-octal-escape": [2], "no-param-reassign": [2], "no-path-concat": [0], "no-plusplus": [0], "no-process-env": [0], "no-process-exit": [2], "no-proto": [2], "no-redeclare": [2], "no-regex-spaces": [2], "no-reserved-keys": [0], "no-restricted-modules": [0], "no-return-assign": [2], "no-script-url": [2], "no-self-compare": [0], "no-sequences": [2], "no-shadow": [2], "no-shadow-restricted-names": [2], "no-space-before-semi": [2], "no-spaced-func": [2], "no-sparse-arrays": [2], "no-sync": [0], "no-ternary": [0], "no-throw-literal": [2], "no-trailing-spaces": [2], "no-undef": [2], "no-undef-init": [2], "no-undefined": [0], "no-underscore-dangle": [2], "no-unreachable": [2], "no-unused-expressions": [2], "no-unused-vars": [1, { "vars": "all", "args": "after-used" }], "no-use-before-define": [2], "no-void": [0], "no-warning-comments": [0, { "terms": ["todo", "fixme", "xxx"], "location": "start" }], "no-with": [2], "no-wrap-func": [2], "one-var": [0], "operator-assignment": [0, "always"], "operator-linebreak": [2, "after"], "padded-blocks": [0], "quote-props": [0], "radix": [0], "semi": [2], "semi-spacing": [2, { "before": false, "after": true }], "sort-vars": [0], "space-after-keywords": [2, "always"], "space-before-function-paren": [2, { "anonymous": "always", "named": "always" }], "space-before-blocks": [0, "always"], "space-in-brackets": [0, "never", { "singleValue": true, "arraysInArrays": false, "arraysInObjects": false, "objectsInArrays": true, "objectsInObjects": true, "propertyName": false }], "space-in-parens": [2, "never"], "space-infix-ops": [2], "space-return-throw-case": [2], "space-unary-ops": [2, { "words": true, "nonwords": false }], "spaced-line-comment": [0, "always"], "strict": [1], "use-isnan": [2], "valid-jsdoc": [0], "valid-typeof": [2], "vars-on-top": [0], "wrap-iife": [2], "wrap-regex": [2], "yoda": [2, "never", { "exceptRange": true }] } } ================================================ FILE: .gitignore ================================================ node_modules .validate.json .jshintrc .jshintignore ================================================ FILE: .travis.yml ================================================ language: node_js node_js: - "0.12" - "0.11" - "0.10" - "iojs" ================================================ FILE: LICENSE ================================================ The MIT License (MIT) Copyright (c) 2015 Eric Elliott Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ================================================ FILE: README.md ================================================ # irecord [![Build Status](https://travis-ci.org/ericelliott/irecord.svg?branch=master)](https://travis-ci.org/ericelliott/irecord) An immutable object map that exposes an RxJS observable. Written for the [Learn JavaScript with Eric Elliott](https://ericelliottjs.com/) online JavaScript course series. ## Status - DEPRECATED - try [lenses](https://medium.com/javascript-scene/lenses-b85976cb0534) or [transducers](https://medium.com/javascript-scene/transducers-efficient-data-processing-pipelines-in-javascript-7985330fe73d) instead. This project was an experiment and is no longer under active development. ## Wait, what is this thing? Imagine a JavaScript object that just stores data. Now imagine that every time you change that object, the object emits a change event. Yeah, kindof like Backbone models, but different. ## What is reactive programming? The concept of reactive programming, and more specifically, how it differs from event listeners and the observer pattern is sometimes hard for beginners. [Resources that might help](./reactive-programming.md). ### How is it different? When you change the value of a key, the previous value doesn't get erased. Instead, it gets added to a history. Every time you make a change, the new object state and the previous object state get emitted with the change event. In other words, you can very easily compare the two objects if you need to see what changed. In fact, if you set a property to the same value as the previous value, no change event gets emitted at all. ### What's this RxJS thing? Instead of subscribing to change events with `.on()`, you could use the RxJS `.subscribe()` method. Maybe later we'll add lots of other neat capabilities that RxJS makes possible. ### Why would I want to use this with React? Pretty simple really, it makes it easy for your components to subscribe to changes in your store. Since it's backed by Immutable.js, you only render when something actually changes, which can save React the trouble of building a whole virtual DOM and diffing that against the actual DOM. Why even start if you know nothing is different? irecord knows when React doesn't have any work to do so you only run `React.render()` when it does. ## Install ``` $ npm install --save irecord ``` ## Use / API ```js import irecord from 'irecord'; const record = irecord({ a: 'a', b: 'b' }); // record.get('a') // => 'a' assert.equal(record.get('a'), 'a', '.get() should return a value for the specified key.'); record.set('c', 'c'); assert.equal(record.get('c'), 'c', '.set() should set the value for the specified key'); record.remove('b'); assert.equal(record.get('b'), undefined, '.remove() should remove the key passed in'); // record.toJS(); // => [Object object] // get record as regular JS object. const obj2 = record.toJS(); assert.deepEqual(record, obj2, '.toJS() should return a JS object'); ``` ## Events ```js const original = { a: 'a', b: 'b' }; const record = irecord(original); // Listen for change events - get current and previous values. record.on('change', ({ value, previous }) => { assert.pass('should emit change events.'); assert.deepEqual(value.toJS(), { a: 'a', b: 'b', c: 'c' }, 'new value should be passed.'); assert.deepEqual(previous.toJS(), original, 'previous value should be passed.'); }); record.set('c', 'c'); ``` ## Rx Observable Here are the Rx Observable methods you can use with irecord instances. ### .subscribe() ``` record.subscribe( ({ value, previous }) => { assert.pass('should emit change events.'); assert.deepEqual(value.toJS(), { a: 'a', b: 'b', c: 'c' }, 'new value should be passed.'); assert.deepEqual(previous.toJS(), original, 'previous value should be passed.'); }, (err) => { assert.fail('err: ' + err); }, () => { assert.pass('complete'); } ); ``` ### .filter() ```js const original = { a: 'a', b: 'b' }; const record = irecord(original); record.filter(({value}) => { return value.toJS().c === 'again'; }).subscribe(({ value }) => { assert.equal(value.toJS().c, 'again', `should filter out changes that don't match the predicate`); }); record.set('a', 'changed'); record.set('c', 'c'); record.set('c', 'again'); ``` ================================================ FILE: build/index.js ================================================ 'use strict'; Object.defineProperty(exports, '__esModule', { value: true }); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; } var _immutable = require('immutable'); var _immutable2 = _interopRequireDefault(_immutable); var _dpath = require('dpath'); var _dpath2 = _interopRequireDefault(_dpath); var _events = require('events'); var _events2 = _interopRequireDefault(_events); var _stampit = require('stampit'); var _stampit2 = _interopRequireDefault(_stampit); var _rx = require('rx'); var _rx2 = _interopRequireDefault(_rx); var irecord = function irecord(obj) { var stamp = undefined, instance = undefined; var history = []; var state = function state() { return history[history.length - 1]; }; var update = function update(value) { if (state() === value) return; var previous = state(); history.push(value); instance.emit('change', { value: value, previous: previous }); }; history.push(_immutable2['default'].fromJS(obj)); stamp = _stampit2['default'].convertConstructor(_events2['default'].EventEmitter).methods({ get: function get(key) { return state().getIn((0, _dpath2['default'])(key)); }, set: function set(key, val) { update(state().setIn((0, _dpath2['default'])(key), val)); return this; }, remove: function remove(key) { update(state().removeIn((0, _dpath2['default'])(key))); return this; }, toJS: function toJS() { return state().toJS(); } }).init(function () { var source = _rx2['default'].Observable.fromEvent(this, 'change', function (ev) { return ev[0]; }); this.subscribe = source.subscribe.bind(source); this.filter = source.filter.bind(source); }); instance = stamp.create(); return _stampit2['default'].extend(instance, { stamp: stamp }); }; exports['default'] = irecord; module.exports = exports['default']; //# sourceMappingURL=index.js.map ================================================ FILE: build/test/basics.js ================================================ 'use strict'; function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; } var _tape = require('tape'); var _tape2 = _interopRequireDefault(_tape); var _indexJs = require('../index.js'); var _indexJs2 = _interopRequireDefault(_indexJs); (0, _tape2['default'])('immutable', function (assert) { var original = { a: 'a', b: 'b' }; var record = (0, _indexJs2['default'])(original); record.set('c', 'c'); assert.deepEqual(original, { a: 'a', b: 'b' }, 'should not mutate original object'); assert.end(); }); (0, _tape2['default'])('immutable deep Array', function (assert) { var input = { a: [1, 2] }; var original = { a: [1, 2] }; var record = (0, _indexJs2['default'])(input); input.a.push(3); assert.deepEqual(original.a, record.get('a').toJS(), 'should not mutate original deep array'); assert.end(); }); (0, _tape2['default'])('change events', function (assert) { assert.plan(3); var original = { a: 'a', b: 'b' }; var record = (0, _indexJs2['default'])(original); record.on('change', function (_ref) { var value = _ref.value; var previous = _ref.previous; assert.pass('should emit change events.'); assert.deepEqual(value.toJS(), { a: 'a', b: 'b', c: 'c' }, 'new value should be passed.'); assert.deepEqual(previous.toJS(), original, 'previous value should be passed.'); }); record.set('c', 'c'); }); (0, _tape2['default'])('.get()', function (assert) { var record = (0, _indexJs2['default'])({ a: 'a', b: 'b' }); assert.equal(record.get('a'), 'a', '.get() should return a value for the specified key.'); assert.end(); }); (0, _tape2['default'])('.set()', function (assert) { var record = (0, _indexJs2['default'])({ a: 'a', b: 'b' }); record.set('c', 'c'); assert.equal(record.get('c'), 'c', '.set() should set the value for the specified key'); assert.end(); }); (0, _tape2['default'])('.set() & .get() deep', function (assert) { var record = (0, _indexJs2['default'])({}); record.set('a.b.c', 'val'); assert.deepEqual(record.get('a.b.c'), 'val', 'passing \'a.b.c\' as the key should set deep in the record.'); assert.end(); }); (0, _tape2['default'])('.toJS', function (assert) { var obj = { a: 'a', b: 'b' }; var record = (0, _indexJs2['default'])(obj); var obj2 = record.toJS(); assert.deepEqual(obj, obj2, '.toJS() should return a JS object'); assert.end(); }); (0, _tape2['default'])('.remove()', function (assert) { var record = (0, _indexJs2['default'])({ a: 'a', b: 'b' }); record.remove('b'); assert.equal(record.get('b'), undefined, '.remove() should remove the key passed in'); assert.end(); }); ================================================ FILE: build/test/index.js ================================================ 'use strict'; require('require-all')(__dirname); ================================================ FILE: build/test/rx.js ================================================ 'use strict'; function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; } var _tape = require('tape'); var _tape2 = _interopRequireDefault(_tape); var _indexJs = require('../index.js'); var _indexJs2 = _interopRequireDefault(_indexJs); (0, _tape2['default'])('.subscribe', function (assert) { assert.plan(3); var original = { a: 'a', b: 'b' }; var record = (0, _indexJs2['default'])(original); record.subscribe(function (_ref) { var value = _ref.value; var previous = _ref.previous; assert.pass('should emit change events.'); assert.deepEqual(value.toJS(), { a: 'a', b: 'b', c: 'c' }, 'new value should be passed.'); assert.deepEqual(previous.toJS(), original, 'previous value should be passed.'); }, function (err) { assert.fail('err: ' + err); }, function () { assert.pass('complete'); }); record.set('c', 'c'); }); (0, _tape2['default'])('.filter', function (assert) { assert.plan(1); var original = { a: 'a', b: 'b' }; var record = (0, _indexJs2['default'])(original); record.filter(function (_ref2) { var value = _ref2.value; return value.toJS().c === 'again'; }).subscribe(function (_ref3) { var value = _ref3.value; assert.equal(value.toJS().c, 'again', 'should filter out changes that don\'t match the predicate'); }); record.set('a', 'changed'); record.set('c', 'c'); record.set('c', 'again'); assert.end(); }); ================================================ FILE: build/test/stampit.js ================================================ 'use strict'; function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; } var _stampit = require('stampit'); var _stampit2 = _interopRequireDefault(_stampit); var _tape = require('tape'); var _tape2 = _interopRequireDefault(_tape); var _indexJs = require('../index.js'); var _indexJs2 = _interopRequireDefault(_indexJs); (0, _tape2['default'])('stamp composition with irecord', function (assert) { assert.plan(1); var record = (0, _indexJs2['default'])({ a: 'a', b: 'b' }); var stamp = (0, _stampit2['default'])({ methods: { countProps: function countProps() { return Object.keys(this.toJS()).length; } } }); var composedRecord = _stampit2['default'].compose(record.stamp, stamp).create(); assert.equal(composedRecord.countProps(), 2, 'should expose irecord methods'); }); ================================================ FILE: package.json ================================================ { "name": "irecord", "version": "1.1.1", "description": "An immutable object map that exposes an RxJS observable. Great for React.", "main": "build/index.js", "scripts": { "init": "rimraf .validate.json && rimraf .jshintrc", "clean": "rimraf build && mkdir -p build/test", "lint": "eslint source && eslint test", "prebuild": "npm run clean", "build": "babel -d build source -s && babel -d build/test test", "test": "node build/test/index.js", "prepublish": "npm run build", "validate": "npm run lint && npm run build && npm test", "validate-dev": "npm run lint && npm run build && npm test | faucet", "audit": "nsp package", "missing": "dependency-check package.json", "extra": "dependency-check package.json --extra --ignore", "ok": "echo 'OK if the dependencies above are all devDependencies.' && echo 'Clean up any unused dependencies.'", "deps": "npm run missing && npm run extra && npm run ok", "precheck": "npm run validate", "check": "npm run audit && npm run deps && npm outdated --depth 0", "precommit": "pre-commit run" }, "pre-commit": [ "check" ], "repository": { "type": "git", "url": "https://github.com/ericelliott/istore.git" }, "keywords": [ "immutable", "rxjs", "reactive", "observable", "store", "react", "flux" ], "author": "Eric Elliott", "license": "MIT", "bugs": { "url": "https://github.com/ericelliott/irecord/issues" }, "homepage": "https://github.com/ericelliott/irecord", "devDependencies": { "babel": "^5.5.7", "babel-eslint": "^3.1.15", "dependency-check": "^2.4.0", "eslint": "^0.22.1", "faucet": "0.0.1", "nsp": "^1.0.1", "precommit-hook": "^2.0.1", "require-all": "^1.1.0", "rimraf": "^2.4.0", "tape": "^4.0.0" }, "dependencies": { "dpath": "^1.0.0", "immutable": "^3.7.3", "rx": "^2.5.3", "stampit": "^2.0.3" } } ================================================ FILE: reactive-programming.md ================================================ ## Learn About Reactive Programming Reactive programming is a programming paradigm oriented around data flows and the propagation of change. In general, reactive programming tools allow you to evaluate data flows as streams and process those streams with functional utilities to filter, map, or manipulate values as they flow through the system. ### Video * [Asynchronous Programming at Netflix](https://www.youtube.com/watch?v=gawmdhCNy-A) [Jafar Husain](https://twitter.com/jhusain) * [What is Reactive Programming?](https://www.youtube.com/watch?v=dwP1TNXE6fc) [Jafar Husain](https://twitter.com/jhusain) explains reactive programming * [Immutability: Putting The Dream Machine To Work](https://www.youtube.com/watch?v=SiFwRtCnxv4) by [David Nolen](https://twitter.com/swannodette) ### Reading * [Introduction to Reactive Programming](https://gist.github.com/staltz/868e7e9bc2a7b8c1f754) * [The Dao of Immutability](https://medium.com/javascript-scene/the-dao-of-immutability-9f91a70c88cd) The Way of the Functional Programmer * [The General Theory of Reactivity](https://github.com/kriskowal/gtor) What is all this talk about reactive? Functional? Promises? This is the beginning of a reactive programming bible. * [Reactive MVC and the Virtual DOM](http://futurice.com/blog/reactive-mvc-and-the-virtual-dom) Great read, even if you're not a React user. ================================================ FILE: source/index.js ================================================ 'use strict'; import immutable from 'immutable'; import dp from 'dpath'; import events from 'events'; import stampit from 'stampit'; import Rx from 'rx'; const irecord = function (obj) { let stamp, instance; const history = []; const state = function () { return history[history.length - 1]; }; const update = function update (value) { if (state() === value) return; const previous = state(); history.push(value); instance.emit('change', {value, previous}); }; history.push(immutable.fromJS(obj)); stamp = stampit.convertConstructor(events.EventEmitter) .methods({ get (key) { return state().getIn(dp(key)); }, set (key, val) { update(state().setIn(dp(key), val)); return this; }, remove (key) { update(state().removeIn(dp(key))); return this; }, toJS () { return state().toJS(); } }) .init(function () { const source = Rx.Observable.fromEvent( this, 'change', (ev) => ev[0]); this.subscribe = source.subscribe.bind(source); this.filter = source.filter.bind(source); }); instance = stamp.create(); return stampit.extend( instance, { stamp } ); }; export default irecord; ================================================ FILE: test/basics.js ================================================ 'use strict'; import test from 'tape'; import irecord from '../index.js'; test('immutable', (assert) => { const original = { a: 'a', b: 'b' }; const record = irecord(original); record.set('c', 'c'); assert.deepEqual(original, { a: 'a', b: 'b' }, 'should not mutate original object'); assert.end(); }); test('immutable deep Array', (assert) => { const input = { a: [1, 2] }; const original = { a: [1, 2] }; const record = irecord(input); input.a.push(3); assert.deepEqual(original.a, record.get('a').toJS(), 'should not mutate original deep array'); assert.end(); }); test('change events', (assert) => { assert.plan(3); const original = { a: 'a', b: 'b' }; const record = irecord(original); record.on('change', ({ value, previous }) => { assert.pass('should emit change events.'); assert.deepEqual(value.toJS(), { a: 'a', b: 'b', c: 'c' }, 'new value should be passed.'); assert.deepEqual(previous.toJS(), original, 'previous value should be passed.'); }); record.set('c', 'c'); }); test('.get()', (assert) => { const record = irecord({ a: 'a', b: 'b' }); assert.equal(record.get('a'), 'a', '.get() should return a value for the specified key.'); assert.end(); }); test('.set()', (assert) => { const record = irecord({ a: 'a', b: 'b' }); record.set('c', 'c'); assert.equal(record.get('c'), 'c', '.set() should set the value for the specified key'); assert.end(); }); test('.set() & .get() deep', assert => { const record = irecord({}); record.set('a.b.c', 'val'); assert.deepEqual(record.get('a.b.c'), 'val', `passing 'a.b.c' as the key should set deep in the record.`); assert.end(); }); test('.toJS', (assert) => { const obj = { a: 'a', b: 'b' }; const record = irecord(obj); const obj2 = record.toJS(); assert.deepEqual(obj, obj2, '.toJS() should return a JS object'); assert.end(); }); test('.remove()', (assert) => { const record = irecord({ a: 'a', b: 'b' }); record.remove('b'); assert.equal(record.get('b'), undefined, '.remove() should remove the key passed in'); assert.end(); }); ================================================ FILE: test/index.js ================================================ 'use strict'; require('require-all')(__dirname); ================================================ FILE: test/rx.js ================================================ 'use strict'; import test from 'tape'; import irecord from '../index.js'; test('.subscribe', (assert) => { assert.plan(3); const original = { a: 'a', b: 'b' }; const record = irecord(original); record.subscribe( ({ value, previous }) => { assert.pass('should emit change events.'); assert.deepEqual(value.toJS(), { a: 'a', b: 'b', c: 'c' }, 'new value should be passed.'); assert.deepEqual(previous.toJS(), original, 'previous value should be passed.'); }, (err) => { assert.fail('err: ' + err); }, () => { assert.pass('complete'); } ); record.set('c', 'c'); }); test('.filter', (assert) => { assert.plan(1); const original = { a: 'a', b: 'b' }; const record = irecord(original); record.filter(({value}) => { return value.toJS().c === 'again'; }).subscribe(({ value }) => { assert.equal(value.toJS().c, 'again', `should filter out changes that don't match the predicate`); }); record.set('a', 'changed'); record.set('c', 'c'); record.set('c', 'again'); assert.end(); }); ================================================ FILE: test/stampit.js ================================================ 'use strict'; import stampit from 'stampit'; import test from 'tape'; import irecord from '../index.js'; test('stamp composition with irecord', (assert) => { assert.plan(1); const record = irecord({ a: 'a', b: 'b' }); const stamp = stampit({ methods: { countProps () { return Object.keys(this.toJS()).length; } } }); const composedRecord = stampit.compose( record.stamp, stamp ).create(); assert.equal(composedRecord.countProps(), 2, 'should expose irecord methods'); });