Skip to content

Commit

Permalink
carbon-mirror -> carbon-indexeddb-mirror
Browse files Browse the repository at this point in the history
  • Loading branch information
Chris Joel committed Apr 21, 2016
1 parent 6cc22f1 commit 60f4e45
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
let transactionId = Symbol('transactionId');
let worker = null;

Polymer.CarbonMirrorClient = class CarbonMirrorClient {
Polymer.CarbonIndexedDBMirrorClient = class CarbonIndexedDBMirrorClient {
constructor(_workerUrl) {
this[workerUrl] = _workerUrl;
this[connected] = false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
let dbName = Symbol('dbName');
let storeName = Symbol('storeName');

class CarbonMirrorWorker {
class CarbonIndexedDBMirrorWorker {
constructor(_dbName='carbon-mirror', _storeName='mirrored_data') {
// Maybe useful in case we want to notify clients of changes..
this[dbName] = _dbName;
Expand All @@ -31,11 +31,10 @@
'error', error => console.error(error));
self.addEventListener(
'message', message => this.handleGlobalMessage(message));
console.log('CarbonPersistenceService started...');
console.log('CarbonIndexedDBMirrorWorker started...');
}

transaction(method, key, value=null) {
console.log.apply(console, arguments);
switch(method) {
case 'get':
return this.get(key);
Expand All @@ -45,7 +44,7 @@
}

get(key) {
return this.dbOpens.then((db) => {
return this.dbOpens.then(db => {
return new Promise((resolve, reject) => {
let transaction = db.transaction(this[storeName], 'readonly');
let store = transaction.objectStore(this[storeName]);
Expand All @@ -58,7 +57,7 @@
}

set(key, value) {
return this.dbOpens.then((db) => {
return this.dbOpens.then(db => {
return new Promise((resolve, reject) => {
let transaction = db.transaction(this[storeName], 'readwrite');
let store = transaction.objectStore(this[storeName]);
Expand All @@ -71,7 +70,6 @@
}

registerClient(port) {
console.log('Registering client', port)
port.addEventListener(
'message', event => this.handleClientMessage(event, port));
this[clientPorts].add(port);
Expand All @@ -80,7 +78,6 @@
}

handleClientMessage(event, port) {
console.log(event.data);
if (!event.data) {
return;
}
Expand All @@ -106,8 +103,9 @@
}
}

self.carbonMirrorWorker = new CarbonMirrorWorker();
self.carbonIndexedDBMirrorWorker = new CarbonIndexedDBMirrorWorker();

self.addEventListener(
'connect', event => carbonMirrorWorker.registerClient(event.ports[0]));
'connect',
event => carbonIndexedDBMirrorWorker.registerClient(event.ports[0]));
})();
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
<link rel="import" href="../../polymer/polymer.html">
<link rel="import" href="../carbon-storage-behavior.html">
<link rel="import" href="../carbon-network-status-behavior.html">
<link rel="import" href="carbon-mirror-client.html">
<dom-module id="carbon-mirror">
<link rel="import" href="carbon-indexeddb-mirror-client.html">
<dom-module id="carbon-indexeddb-mirror">
<script>
(() => {
'use strict';

Polymer({
is: 'carbon-mirror',
is: 'carbon-indexeddb-mirror',

behaviors: [
Polymer.CarbonStorageBehavior,
Expand All @@ -24,12 +24,12 @@
workerUrl: {
type: String,
value() {
return this.resolveUrl('./carbon-mirror-worker.js');
return this.resolveUrl('./carbon-indexeddb-mirror-worker.js');
}
},

client: {
type: Polymer.CarbonMirrorClient,
type: Polymer.CarbonIndexedDBMirrorClient,
computed: '__computeClient(workerUrl)'
},

Expand All @@ -48,12 +48,10 @@
},

setStoredValue(path, value) {
console.log('set', arguments);
return this.client.transaction('set', this.store, this.data);
},

getStoredValue(path) {
console.log('get', arguments);
return this.client.transaction('get', this.store);
},

Expand All @@ -62,7 +60,7 @@
},

__computeClient(workerUrl, workerScope) {
return new Polymer.CarbonMirrorClient(workerUrl);
return new Polymer.CarbonIndexedDBMirrorClient(workerUrl);
},

__updatePersistedData(client, online, data) {
Expand Down
6 changes: 3 additions & 3 deletions demo/note-app.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<link rel="import" href="../../paper-fab/paper-fab.html">
<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Roboto+Slab:400,700">

<link rel="import" href="../carbon-mirror/carbon-mirror.html">
<link rel="import" href="../carbon-indexeddb-mirror/carbon-indexeddb-mirror.html">
<link rel="import" href="../carbon-firebase/carbon-firebase-query.html">
<link rel="import" href="note-app/na-note.html">
<link rel="import" href="note-app/na-editor.html">
Expand Down Expand Up @@ -96,12 +96,12 @@ <h1>Notes</h1>
data="{{data}}">
</carbon-firebase-query>

<carbon-mirror
<carbon-indexeddb-mirror
store="notes"
data="{{data}}"
persisted-data="{{persistedData}}"
online="{{online}}">
</carbon-mirror>
</carbon-indexeddb-mirror>

<div class="notes">
<template is="dom-repeat" items="[[persistedData]]" as="note">
Expand Down

0 comments on commit 60f4e45

Please sign in to comment.