Repository: philholden/redux-swarmlog
Branch: master
Commit: 8b53d605876f
Files: 44
Total size: 46.4 KB
Directory structure:
gitextract_retdfhs6/
├── .babelrc
├── .builderrc
├── .editorconfig
├── .eslintrc
├── .gitignore
├── .npmignore
├── .travis.yml
├── .travis.yml-old
├── LICENSE
├── README.md
├── consume.html
├── devServer.js
├── examples/
│ ├── consume.html
│ ├── index.html
│ ├── keys.json
│ ├── publish.html
│ └── src/
│ ├── __tests__/
│ │ ├── index.test.js
│ │ └── null-compiler.js
│ ├── actions/
│ │ └── index.js
│ ├── api.js
│ ├── components/
│ │ ├── app.js
│ │ ├── song-item-container.js
│ │ ├── song-list-container.js
│ │ ├── song-store-item-container.js
│ │ ├── song-store-list-container.js
│ │ └── song-store-sync-container.js
│ ├── consume.js
│ ├── generate-keys.js
│ ├── index.js
│ ├── publish.js
│ ├── reducers/
│ │ ├── index.js
│ │ └── song-stores.js
│ └── sagas/
│ └── index.js
├── index.html
├── keys.json
├── package.json
├── publish.html
├── src/
│ ├── __tests__/
│ │ ├── index.test.js
│ │ └── null-compiler.js
│ ├── index.js
│ └── redux-swarmlog.js
├── webpack.config.dev.js
├── webpack.config.lib.js
└── webpack.config.prod.js
================================================
FILE CONTENTS
================================================
================================================
FILE: .babelrc
================================================
{
"presets": ["react", "es2015", "stage-1"],
"env": {
"development": {
"presets": ["react-hmre"]
},
"lib": {
"plugins": [
[
"babel-plugin-webpack-loaders",
{
"config": "./webpack.config.lib.js",
"verbose": false,
}
]
]
}
}
}
================================================
FILE: .builderrc
================================================
---
archetypes:
- component-archetype
================================================
FILE: .editorconfig
================================================
# EditorConfig helps developers define and maintain consistent
# coding styles between different editors and IDEs
# editorconfig.org
root = true
[*]
# Change these settings to your own preference
indent_style = space
indent_size = 2
# We recommend you to keep these unchanged
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true
[*.md]
trim_trailing_whitespace = false
================================================
FILE: .eslintrc
================================================
{
"extends": "rackt",
"ecmaFeatures": {
"jsx": true,
"modules": true
},
"env": {
"browser": true,
"node": true,
"mocha": true
},
"parser": "babel-eslint",
"rules": {
"quotes": [2, "single"],
"strict": [2, "never"],
"babel/generator-star-spacing": 1,
"babel/object-shorthand": 1,
"babel/no-await-in-loop": 1,
"react/jsx-uses-react": 2,
"react/jsx-uses-vars": 2,
"react/react-in-jsx-scope": 2
},
"plugins": [
"babel",
"react"
]
}
================================================
FILE: .gitignore
================================================
.DS_Store
node_modules
npm-debug.log
dist
.nyc_output
coverage
lib
================================================
FILE: .npmignore
================================================
.DS_Store
*.log
src
test
examples
docs
demo
coverage
*.sublime-project
*.sublime-workspace
================================================
FILE: .travis.yml
================================================
sudo: false
language: node_js
cache:
directories:
- node_modules
branches:
only:
- master
notifications:
email: false
node_js:
- "5.1.0"
before_install:
- npm i -g npm@^3.0.0
before_script:
- npm prune
script:
- npm run test:cover
- npm run check-coverage
- npm run build
after_success:
- npm run report-coverage
- npm run semantic-release
branches:
except:
- "/^v\\d+\\.\\d+\\.\\d+$/"
================================================
FILE: .travis.yml-old
================================================
sudo: false
language: node_js
cache:
directories:
- node_modules
branches:
only:
- master
notifications:
email: false
node_js:
- "5.1.0"
before_install:
- npm i -g npm@^3.0.0
before_script:
- npm prune
script:
- npm run test:cover
- npm run check-coverage
- npm run build
after_success:
- npm run report-coverage
- npm run semantic-release
branches:
except:
- "/^v\\d+\\.\\d+\\.\\d+$/"
================================================
FILE: LICENSE
================================================
Creative Commons Legal Code
CC0 1.0 Universal
CREATIVE COMMONS CORPORATION IS NOT A LAW FIRM AND DOES NOT PROVIDE
LEGAL SERVICES. DISTRIBUTION OF THIS DOCUMENT DOES NOT CREATE AN
ATTORNEY-CLIENT RELATIONSHIP. CREATIVE COMMONS PROVIDES THIS
INFORMATION ON AN "AS-IS" BASIS. CREATIVE COMMONS MAKES NO WARRANTIES
REGARDING THE USE OF THIS DOCUMENT OR THE INFORMATION OR WORKS
PROVIDED HEREUNDER, AND DISCLAIMS LIABILITY FOR DAMAGES RESULTING FROM
THE USE OF THIS DOCUMENT OR THE INFORMATION OR WORKS PROVIDED
HEREUNDER.
Statement of Purpose
The laws of most jurisdictions throughout the world automatically confer
exclusive Copyright and Related Rights (defined below) upon the creator
and subsequent owner(s) (each and all, an "owner") of an original work of
authorship and/or a database (each, a "Work").
Certain owners wish to permanently relinquish those rights to a Work for
the purpose of contributing to a commons of creative, cultural and
scientific works ("Commons") that the public can reliably and without fear
of later claims of infringement build upon, modify, incorporate in other
works, reuse and redistribute as freely as possible in any form whatsoever
and for any purposes, including without limitation commercial purposes.
These owners may contribute to the Commons to promote the ideal of a free
culture and the further production of creative, cultural and scientific
works, or to gain reputation or greater distribution for their Work in
part through the use and efforts of others.
For these and/or other purposes and motivations, and without any
expectation of additional consideration or compensation, the person
associating CC0 with a Work (the "Affirmer"), to the extent that he or she
is an owner of Copyright and Related Rights in the Work, voluntarily
elects to apply CC0 to the Work and publicly distribute the Work under its
terms, with knowledge of his or her Copyright and Related Rights in the
Work and the meaning and intended legal effect of CC0 on those rights.
1. Copyright and Related Rights. A Work made available under CC0 may be
protected by copyright and related or neighboring rights ("Copyright and
Related Rights"). Copyright and Related Rights include, but are not
limited to, the following:
i. the right to reproduce, adapt, distribute, perform, display,
communicate, and translate a Work;
ii. moral rights retained by the original author(s) and/or performer(s);
iii. publicity and privacy rights pertaining to a person's image or
likeness depicted in a Work;
iv. rights protecting against unfair competition in regards to a Work,
subject to the limitations in paragraph 4(a), below;
v. rights protecting the extraction, dissemination, use and reuse of data
in a Work;
vi. database rights (such as those arising under Directive 96/9/EC of the
European Parliament and of the Council of 11 March 1996 on the legal
protection of databases, and under any national implementation
thereof, including any amended or successor version of such
directive); and
vii. other similar, equivalent or corresponding rights throughout the
world based on applicable law or treaty, and any national
implementations thereof.
2. Waiver. To the greatest extent permitted by, but not in contravention
of, applicable law, Affirmer hereby overtly, fully, permanently,
irrevocably and unconditionally waives, abandons, and surrenders all of
Affirmer's Copyright and Related Rights and associated claims and causes
of action, whether now known or unknown (including existing as well as
future claims and causes of action), in the Work (i) in all territories
worldwide, (ii) for the maximum duration provided by applicable law or
treaty (including future time extensions), (iii) in any current or future
medium and for any number of copies, and (iv) for any purpose whatsoever,
including without limitation commercial, advertising or promotional
purposes (the "Waiver"). Affirmer makes the Waiver for the benefit of each
member of the public at large and to the detriment of Affirmer's heirs and
successors, fully intending that such Waiver shall not be subject to
revocation, rescission, cancellation, termination, or any other legal or
equitable action to disrupt the quiet enjoyment of the Work by the public
as contemplated by Affirmer's express Statement of Purpose.
3. Public License Fallback. Should any part of the Waiver for any reason
be judged legally invalid or ineffective under applicable law, then the
Waiver shall be preserved to the maximum extent permitted taking into
account Affirmer's express Statement of Purpose. In addition, to the
extent the Waiver is so judged Affirmer hereby grants to each affected
person a royalty-free, non transferable, non sublicensable, non exclusive,
irrevocable and unconditional license to exercise Affirmer's Copyright and
Related Rights in the Work (i) in all territories worldwide, (ii) for the
maximum duration provided by applicable law or treaty (including future
time extensions), (iii) in any current or future medium and for any number
of copies, and (iv) for any purpose whatsoever, including without
limitation commercial, advertising or promotional purposes (the
"License"). The License shall be deemed effective as of the date CC0 was
applied by Affirmer to the Work. Should any part of the License for any
reason be judged legally invalid or ineffective under applicable law, such
partial invalidity or ineffectiveness shall not invalidate the remainder
of the License, and in such case Affirmer hereby affirms that he or she
will not (i) exercise any of his or her remaining Copyright and Related
Rights in the Work or (ii) assert any associated claims and causes of
action with respect to the Work, in either case contrary to Affirmer's
express Statement of Purpose.
4. Limitations and Disclaimers.
a. No trademark or patent rights held by Affirmer are waived, abandoned,
surrendered, licensed or otherwise affected by this document.
b. Affirmer offers the Work as-is and makes no representations or
warranties of any kind concerning the Work, express, implied,
statutory or otherwise, including without limitation warranties of
title, merchantability, fitness for a particular purpose, non
infringement, or the absence of latent or other defects, accuracy, or
the present or absence of errors, whether or not discoverable, all to
the greatest extent permissible under applicable law.
c. Affirmer disclaims responsibility for clearing rights of other persons
that may apply to the Work or any use thereof, including without
limitation any person's Copyright and Related Rights in the Work.
Further, Affirmer disclaims responsibility for obtaining any necessary
consents, permissions or other rights required for any use of the
Work.
d. Affirmer understands and acknowledges that Creative Commons is not a
party to this document and has no duty or obligation with respect to
this CC0 or use of the Work.
================================================
FILE: README.md
================================================
# Redux Swarmlog
[](https://travis-ci.org/philholden/redux-swarmlog) [](http://npm.im/@philholden/redux-swarmlog)
[](http://www.youtube.com/watch?v=M99djS07Ph8)
_(Click image to watch React Europe lightning video)_

_(Click image to watch Egghead.io intro video)_
A super simple way of writing distributed Redux applications. The [Redux](https://github.com/reactjs/redux) action log is persisted in an IndexDB and synced with other peers via a [WebRTC Swarm](https://github.com/mafintosh/webrtc-swarm) using [Swarmlog](https://github.com/substack/swarmlog).
When an application reloads the Redux store is initialsed by reducing all the persisted actions in the IndexDB and syncing any new actions from remote peers. Watch the Egghead video above to find out more.
## Pros
* offline data by default
* super simple mental model for writing distributed apps
* UIs update automatically as remote actions come in
* works offline by default
* scales globally for free with no bandwidth or storage costs for the developer
* the developer is not responsible for client data
* friends not cooperations hold user data
* public / private key authentication is lighter weight than user accounts
* time travel
## Cons
* Action logs use more bandwidth than raw data so initial sync could be slow for a very long log.
__workaround:__ Break down long logs into lots of smaller logs e.g. log per month, week or day. Only fetch the most recent log if its all thats needed
* Extra storage space needed on client
__workaround:__ The price of SSDs is falling very rapidly. Stop thinking about cloud and thin client, but cache encrypted data where it is needed. This gives privacy, enables working offline, provides backups and can act as a CDN. Once you start using a distributed system like Git you soon stop thinking about the extra space it requires.
* Permanence: even if an action deletes an item it can still be retrieved from the log.
__workaround:__ Use a log for versioning other logs. Every so often the main log is reduced and a single action is written to a new log which creates the store in the current state. The old log is marked as stale in the version log and its database is deleted (purging old actions).
* Can't get most up to date data if the peer holding it is offline
__workaround:__ A small device like a Raspberry PI kept online should be all that is needed to make sure there is always at least one up to date source of truth. With 5G and IoT we are heading towards an era of always online small connected devices. Let's start thinking that way now.
## Play to Strengths
Redux Swarmlog works well for apps that support some kind of physical live event. Because you know the action log will be short and the users will be online at the same time. Examples might be providing subtitles via mobile phone for a theatre show or letting a teacher see in realtime how each individuals in a class is answering a question.
================================================
FILE: consume.html
================================================
React Transform Boilerplate
================================================
FILE: devServer.js
================================================
var path = require('path') // eslint-disable-line no-var
var express = require('express') // eslint-disable-line no-var
var webpack = require('webpack') // eslint-disable-line no-var
var config = require('./webpack.config.dev') // eslint-disable-line no-var
var compression = require('compression') // eslint-disable-line no-var
var ssbKeys = require('ssb-keys')
// var requestProxy = require('express-request-proxy')
// var objectAssign = require('object-assign')
var app = express() // eslint-disable-line no-var
var server = require('http').createServer(app) // eslint-disable-line no-var
var io = require('socket.io')(server) // eslint-disable-line no-var
var compiler = webpack(config) // eslint-disable-line no-var
var port = 3000 // eslint-disable-line no-var
app.use(require('webpack-dev-middleware')(compiler, {
noInfo: true,
publicPath: config.output.publicPath
}))
app.use(require('webpack-hot-middleware')(compiler))
app.use(compression({
threshold: 512
}))
app.use('/', express.static('.'))
app.get('/keys/', (req, res) => {
res.setHeader('Content-Type', 'application/json')
res.send(JSON.stringify(require('ssb-keys').generate()))
})
// app.all('*', function(req, res, next) {
// var url = require('url').parse(req.url)
// var conf = objectAssign({}, req, {
// url: 'http://127.0.0.1:8888' + url.pathname,
// timeout: 120000
// })
// requestProxy(conf)(req, res, next)
// })
// app.get('*', function (req, res) {
// res.sendFile(path.join(__dirname, 'index.html'))
// })
server.listen(port, '0.0.0.0', function (err) {
if (err) {
console.log(err) // eslint-disable-line no-console
return
}
console.log('Listening at http://localhost:' + port) // eslint-disable-line no-console
})
io.on('connection', function (socket) {
io.set('origins', '*:*')
console.log('connected') // eslint-disable-line no-console
socket.emit('update', 'connected')
socket.on('single', function () {
socket.emit('update', 'single')
})
socket.on('publish', function (data) {
io.sockets.emit('update', data)
})
})
================================================
FILE: examples/consume.html
================================================
React Transform Boilerplate
================================================
FILE: examples/index.html
================================================
React Transform Boilerplate
================================================
FILE: examples/keys.json
================================================
{
"curve": "ed25519",
"public": "q8oQyaB0t9k8bAog6om+q86FRbBoYUklC0eQToR+nw8=.ed25519",
"private": "PmS89eOtLC35JJlcRMquh6qS8oHG4uZpQQcpw3aRHHWryhDJoHS32TxsCiDqib6rzoVFsGhhSSULR5BOhH6fDw==.ed25519",
"id": "@q8oQyaB0t9k8bAog6om+q86FRbBoYUklC0eQToR+nw8=.ed25519"
}
================================================
FILE: examples/publish.html
================================================
React Transform Boilerplate
================================================
FILE: examples/src/__tests__/index.test.js
================================================
import test from 'ava'
import is from 'is_js'
import React from 'react'
import { createRenderer } from 'react-addons-test-utils'
import expect from 'expect'
import expectJSX from 'expect-jsx'
import { HelloWorld } from '../App'
expect.extend(expectJSX)
test('is an array of numbers', t => {
t.true(
[ 1, 2, 3 ].every(item => typeof item === 'number')
)
})
test('1 is in array', t => {
t.true(
is.inArray(1, [ 1, 2, 3 ])
)
})
test('MyComponent default render', () => {
const renderer = createRenderer()
renderer.render(
)
expect(
renderer.getRenderOutput()
)
.toEqualJSX(