Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

React Example #5

Merged
merged 6 commits into from
Dec 6, 2016
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions examples/react-example/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# See http://help.github.com/ignore-files/ for more about ignoring files.

# dependencies
node_modules

# testing
coverage

# production
build

# misc
.DS_Store
.env
npm-debug.log
1,123 changes: 1,123 additions & 0 deletions examples/react-example/README.md

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions examples/react-example/dist/.gittouch
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

70 changes: 70 additions & 0 deletions examples/react-example/dist/lib/Database.schemas.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
'use strict';

Object.defineProperty(exports, "__esModule", {
value: true
});
exports.socket = exports.collections = exports.administration = undefined;

var _RxSchema = require('./RxSchema');

var RxSchema = _interopRequireWildcard(_RxSchema);

function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj.default = obj; return newObj; } }

var administration = exports.administration = RxSchema.create({
properties: {
key: {
type: 'string',
primary: true
},
value: {
type: 'string'
}
},
required: ['value']
});

var collections = exports.collections = RxSchema.create({
properties: {
name: {
type: 'string',
primary: true
},
schemaHash: {
type: 'string'
}
},
required: ['schemaHash']
});

var socket = exports.socket = RxSchema.create({
properties: {
it: {
description: 'token of the db-instance',
type: 'string',
index: true
},
t: {
description: 'timestamp unix',
type: 'number',
min: 100
},
op: {
description: 'operation-code of the changeEvent',
type: 'string'
},
col: {
description: 'collection-name',
type: 'string'
},
doc: {
description: 'Document._id',
type: 'string'
},
v: {
description: 'the value, maybe encrypted or JSON.stringify',
type: 'string'
}
},
required: ['it', 't', 'op']
});
28 changes: 28 additions & 0 deletions examples/react-example/dist/lib/PouchDB.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
'use strict';

Object.defineProperty(exports, "__esModule", {
value: true
});

var _pouchdbCore = require('pouchdb-core');

var _pouchdbCore2 = _interopRequireDefault(_pouchdbCore);

var _pouchdbFind = require('pouchdb-find');

var PouchDBFind = _interopRequireWildcard(_pouchdbFind);

function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj.default = obj; return newObj; } }

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

/**
* this handles the pouchdb-instance
* to easy add modules and manipulate things
* Adapters can be found here:
* @link https://github.com/pouchdb/pouchdb/tree/master/packages/node_modules
*/
_pouchdbCore2.default.plugin(PouchDBFind);

// pouchdb-find
exports.default = _pouchdbCore2.default;
97 changes: 97 additions & 0 deletions examples/react-example/dist/lib/RxChangeEvent.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
'use strict';

Object.defineProperty(exports, "__esModule", {
value: true
});

var _classCallCheck2 = require('babel-runtime/helpers/classCallCheck');

var _classCallCheck3 = _interopRequireDefault(_classCallCheck2);

var _createClass2 = require('babel-runtime/helpers/createClass');

var _createClass3 = _interopRequireDefault(_createClass2);

exports.fromJSON = fromJSON;
exports.fromPouchChange = fromPouchChange;
exports.create = create;

var _util = require('./util');

var util = _interopRequireWildcard(_util);

function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj.default = obj; return newObj; } }

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

var RxChangeEvent = function () {
function RxChangeEvent(data) {
(0, _classCallCheck3.default)(this, RxChangeEvent);

this.data = data;
}

(0, _createClass3.default)(RxChangeEvent, [{
key: 'toJSON',
value: function toJSON() {
var ret = {
op: this.data.op,
t: this.data.t,
db: this.data.db,
it: this.data.it
};
if (this.data.col) ret.col = this.data.col;
if (this.data.doc) ret.doc = this.data.doc;
if (this.data.v) ret.v = this.data.v;
return ret;
}
}, {
key: 'isIntern',
value: function isIntern() {
if (this.data.col && this.data.col.charAt(0) == '_') return true;
return false;
}
}, {
key: 'hash',
value: function hash() {
if (!this._hash) this._hash = util.hash(this.data);
return this._hash;
}
}]);
return RxChangeEvent;
}(); /**
* RxChangeEvents a emitted when something in the database changes
* they can be grabbed by the observables of database, collection and document
*/

function fromJSON(data) {
return new RxChangeEvent(data);
}

function fromPouchChange(changeDoc, collection) {

var op = changeDoc._rev.startsWith('1-') ? 'RxDocument.save' : 'RxDocument.insert';
var data = {
op: op,
t: new Date().getTime(),
db: 'remote',
col: collection.name,
it: collection.database.token,
doc: changeDoc._id,
v: changeDoc
};
return new RxChangeEvent(data);
}

function create(op, database, collection, doc, value) {
var data = {
op: op,
t: new Date().getTime(),
db: database.prefix,
it: database.token
};
if (collection) data.col = collection.name;
if (doc) data.doc = doc.rawData._id;
if (value) data.v = value;
return new RxChangeEvent(data);
}
Loading