Skip to content

Commit

Permalink
Merge pull request #192 from firebase/2.0-preview
Browse files Browse the repository at this point in the history
2.0-preview
  • Loading branch information
e111077 authored May 12, 2017
2 parents 26da261 + 2177bd7 commit 1a75a3c
Show file tree
Hide file tree
Showing 9 changed files with 150 additions and 72 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
bower_components
bower_components*
bower-*.json
27 changes: 22 additions & 5 deletions bower.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "polymerfire",
"version": "0.11.2",
"version": "2.0.0",
"authors": [
"Firebase"
],
Expand All @@ -18,12 +18,29 @@
"/test/"
],
"dependencies": {
"polymer": "Polymer/polymer#^1.2",
"polymer": "polymer/polymer#^2.0.0-rc.3",
"firebase": ">= 3.5.1 < 4.0",
"app-storage": "polymerelements/app-storage#^1.0.0"
"app-storage": "PolymerElements/app-storage#2.0-preview"
},
"devDependencies": {
"iron-component-page": "PolymerElements/iron-component-page#^1.0",
"web-component-tester": "^4.0.0"
"iron-component-page": "PolymerElements/iron-component-page#2.0-preview",
"note-app-elements": "polymerlabs/note-app-elements#2.0-preview",
"webcomponentsjs": "webcomponents/webcomponentsjs#^1.0.0-rc.4",
"web-component-tester": "Polymer/web-component-tester#^6.0.0-prerelease.6"
},
"variants": {
"1.x": {
"dependencies": {
"polymer": "Polymer/polymer#^1.2",
"firebase": ">= 3.5.1 < 4.0",
"app-storage": "polymerelements/app-storage#^0.9.0"
},
"devDependencies": {
"iron-component-page": "PolymerElements/iron-component-page#^1.0",
"note-app-elements": "polymerlabs/note-app-elements",
"web-component-tester": "^4.0.0",
"webcomponentsjs": "webcomponents/webcomponentsjs#^0.7.0"
}
}
}
}
61 changes: 38 additions & 23 deletions demo/firebase-messaging.html
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,13 @@
window.addEventListener('WebComponentsReady', function() {
if (navigator.serviceWorker) {
navigator.serviceWorker.register('firebase-messaging-sw.js').then(function(sw) {
var app = document.getElementById('app');

// Polymer 2.0 compat
if (Polymer.Element) {
app = app.parentNode;
}

app.$.messaging.activate(sw);
});
}
Expand All @@ -70,40 +77,48 @@ <h1>firebase-messaging demo</h1>
To actually test receipt of push messages, you will need to clone the demo and modify the
<code>messagingSenderId</code> in this file and in <code>firebase-messaging-sw.js</code>
in this directory.</p>
<template is="dom-bind" id="app">
<firebase-messaging id="messaging"
active="{{active}}"
token="{{token}}"
status-known="{{statusKnown}}"
last-message="{{lastMessage}}"
on-message="logit"
custom-sw>
</firebase-messaging>
<main>
<div hidden$="[[!statusKnown]]">
<button hidden$="[[active]]" on-click="requestMessaging">Request Notifications Permission</button>
<table id="table" hidden$="[[!active]]">
<tr><th>Token</th><td>[[token]]</td></tr>
<tr><th>Last&nbsp;Message</th><td><pre>[[json(lastMessage)]]</pre></td></tr>
</table>
<dom-bind>
<template is="dom-bind" id="app">
<firebase-messaging id="messaging"
active="{{active}}"
token="{{token}}"
status-known="{{statusKnown}}"
last-message="{{lastMessage}}"
on-message="logit"
custom-sw>
</firebase-messaging>
<main>
<div hidden$="[[!statusKnown]]">
<button hidden$="[[active]]" on-click="requestMessaging">Request Notifications Permission</button>
<table id="table" hidden$="[[!active]]">
<tr><th>Token</th><td>[[token]]</td></tr>
<tr><th>Last&nbsp;Message</th><td><pre>[[json(lastMessage)]]</pre></td></tr>
</table>

<h3>Message Log</h3>
<pre id="log" hidden$="[[!active]]"></pre>
</div>
</main>
</template>
<h3>Message Log</h3>
<pre id="log" hidden$="[[!active]]"></pre>
</div>
</main>
</template>
</dom-bind>
<script>
var app = document.getElementById('app');

// Polymer 2.0 compat
if (Polymer.Element) {
app = app.parentNode;
}

app.requestMessaging = function() {
return app.$.messaging.requestPermission();
return this.$.messaging.requestPermission();
}

app.json = function(val) {
return JSON.stringify(val || null, null, 2);
}

app.logit = function(e) {
app.$.log.innerHTML = JSON.stringify(e.detail.message) + "\n" + app.$.log.innerHTML;
this.$.log.innerHTML = JSON.stringify(e.detail.message) + "\n" + app.$.log.innerHTML;
}
</script>
</body>
Expand Down
7 changes: 7 additions & 0 deletions firebase-app.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@

<link rel="import" href="../polymer/polymer.html">
<link rel="import" href="firebase-app-script.html">
<!-- TODO(cdata): Remove all of the imports below this line when it is possible
to lazy load Firebase scripts alongside Custom Elements v1 upgrade order -->
<link rel="import" href="firebase-database-script.html">
<link rel="import" href="firebase-auth-script.html">
<link rel="import" href="firebase-storage-script.html">
<link rel="import" href="firebase-messaging-script.html">
<dom-module id="firebase-app">
<script>
(function() {
Expand Down Expand Up @@ -116,6 +122,7 @@
}

firebase.initializeApp.apply(firebase, init);
this.fire('firebase-app-initialized');
} else {
return null;
}
Expand Down
7 changes: 7 additions & 0 deletions firebase-common-behavior.html
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,13 @@
}
} catch (e) {
// appropriate app hasn't been initialized yet
var self = this;
window.addEventListener('firebase-app-initialized',
function onFirebaseAppInitialized(event) {
window.removeEventListener(
'firebase-app-initialized', onFirebaseAppInitialized);
self.__appNameChanged(self.appName);
});
}
},

Expand Down
8 changes: 8 additions & 0 deletions firebase-query.html
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,14 @@
}

if (query) {
if(this._onOnce){ // remove handlers before adding again. Otherwise we get data multiplying
query.off('child_added', this.__onFirebaseChildAdded, this);
query.off('child_removed', this.__onFirebaseChildRemoved, this);
query.off('child_changed', this.__onFirebaseChildChanged, this);
query.off('child_moved', this.__onFirebaseChildMoved, this);
}

this._onOnce = true;
query.on('child_added', this.__onFirebaseChildAdded, this.__onError, this);
query.on('child_removed', this.__onFirebaseChildRemoved, this.__onError, this);
query.on('child_changed', this.__onFirebaseChildChanged, this.__onError, this);
Expand Down
69 changes: 42 additions & 27 deletions test/firebase-auth.html
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,22 @@
</template>
</test-fixture>

<test-fixture id="DynamicAuth">
<template>
<firebase-auth
app-name="test">
</firebase-auth>
</template>
</test-fixture>

<test-fixture id="DynamicAuth">
<template>
<firebase-auth
app-name="test">
</firebase-auth>
</template>
</test-fixture>

<script>
suite('firebase-auth', function() {
var authElement;
Expand Down Expand Up @@ -74,33 +90,32 @@
expect(originalElement.statusKnown).to.be.equal(false);

originalElement.signInWithEmailAndPassword(email, 'polyfiretestdomain')
.then(function (user) {
//Verify the sign in results
expect(user.uid).to.be.ok;
expect(originalElement.statusKnown).to.be.equal(true);
expect(user.email).to.be.equal(email);

//Create another firebase element
var dynamicAuth = document.createElement("firebase-auth");

//Verify the initial state: statusKnown = false and user is null
dynamicAuth.appName='test';
expect(dynamicAuth.user).to.be.equal(null);
expect(dynamicAuth.statusKnown).to.be.equal(false);

//Wait for the status-known event to be thrown (set in
dynamicAuth.addEventListener('status-known-changed', function(event) {
if (event.detail.value) {
//Verify the final state: statusKnown = false and user is null
expect(dynamicAuth.statusKnown).to.be.equal(true);
expect(dynamicAuth.user.uid).to.be.ok;
expect(dynamicAuth.user.email).to.be.equal(email);
done();
} else {
expect(dynamicAuth.statusKnown).to.be.equal(false);
}
});
});
.then(function (user) {
//Verify the sign in results
expect(user.uid).to.be.ok;
expect(originalElement.statusKnown).to.be.equal(true);
expect(user.email).to.be.equal(email);

//Create another firebase element
var dynamicAuth = fixture("DynamicAuth");

//Verify the initial state: statusKnown = false and user is null
expect(dynamicAuth.user).to.be.equal(null);
expect(dynamicAuth.statusKnown).to.be.equal(false);

//Wait for the status-known event to be thrown (set in
dynamicAuth.addEventListener('status-known-changed', function(event) {
if (event.detail.value) {
//Verify the final state: statusKnown = false and user is null
expect(dynamicAuth.statusKnown).to.be.equal(true);
expect(dynamicAuth.user.uid).to.be.ok;
expect(dynamicAuth.user.email).to.be.equal(email);
done();
} else {
expect(dynamicAuth.statusKnown).to.be.equal(false);
}
});
});
});


Expand Down
1 change: 1 addition & 0 deletions test/firebase-document.html
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
<script src="../../webcomponentsjs/webcomponents-lite.js"></script>
<script src="../../web-component-tester/browser.js"></script>

<link rel="import" href="../polymerfire.html">
<link rel="import" href="../../app-storage/test/app-storage-compatibility-suite.html">
<link rel="import" href="../firebase-app.html">
<link rel="import" href="../firebase-document.html">
Expand Down
39 changes: 23 additions & 16 deletions test/firebase-query.html
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,25 @@
</template>
</test-fixture>

<test-fixture id="DomRepeatQuery">
<template is="dom-template">
<firebase-query app-name="test" path="/list" data="{{data}}"></firebase-query>
<template is="dom-repeat" items="[[data]]">
<dom-module id="dom-repeat-query">
<template>
<firebase-query id="query" app-name="test" path="/list" data="{{data}}"></firebase-query>
<template id="domRepeat" is="dom-repeat" items="[[data]]">
<div>[[item.val]]</div>
</template>
</template>
</template>
<script>
Polymer({
is: 'dom-repeat-query'
});
</script>
</dom-module>

<test-fixture id="DomRepeatQuery">
<template>
<dom-repeat-query></dom-repeat-query>
</template>
</test-fixture>

<test-fixture id="TwoQueries">
Expand Down Expand Up @@ -332,17 +344,11 @@
var domRepeat;

setup(function() {
var elements = fixture('DomRepeatQuery', {
data: []
});
// NOTE(cdata): This works around a bug in `dom-template`. Track
// polymerelements/test-fixture#31 and remove this when that has been
// resolved:
var tmpl = document.querySelector('#DomRepeatQuery').fixtureTemplates[0];
tmpl._parentProps = {};

domRepeat = elements[1];
query = elements[0];
var elements = fixture('DomRepeatQuery');
elements.data = [];

domRepeat = elements.$.domRepeat;
query = elements.$.query;
query.path = root + '/list';
return query.transactionsComplete;
});
Expand All @@ -353,7 +359,8 @@
return setFirebaseValue(
query.path + '/' + query.data[0].$key + '/val', object.val + 1);
}).then(function() {
expect(domRepeat._instances[0].item).to.be.eql(query.data[0]);
var instances = domRepeat._instances || domRepeat.__instances;
expect(instances[0].item).to.be.eql(query.data[0]);
});
});
});
Expand Down

0 comments on commit 1a75a3c

Please sign in to comment.