Skip to content

Commit

Permalink
Merge pull request #79 from ondras/firebase-update
Browse files Browse the repository at this point in the history
updated the firebase api/sdk
  • Loading branch information
ondras authored Oct 2, 2018
2 parents 3a4c0d9 + 439990b commit 9e94038
Show file tree
Hide file tree
Showing 4 changed files with 85 additions and 27 deletions.
8 changes: 5 additions & 3 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@
<title>My Mind</title>
<link rel="icon" href="favicon.ico" />
<script src="my-mind.js"></script>
<script src="https://cdn.firebase.com/js/client/1.0.15/firebase.js"></script>
<script src="https://cdn.firebase.com/js/simple-login/1.5.0/firebase-simple-login.js"></script>
<script src="https://www.gstatic.com/firebasejs/5.5.2/firebase-app.js"></script>
<script src="https://www.gstatic.com/firebasejs/5.5.2/firebase-database.js"></script>
<script src="https://www.gstatic.com/firebasejs/5.5.2/firebase-auth.js"></script>

<link rel="stylesheet" href="css/font.css" />
<link rel="stylesheet" href="css/style.css" />
<link rel="stylesheet" href="css/print.css" media="print" />
Expand Down Expand Up @@ -930,7 +932,7 @@ <h3></h3>
<option value="facebook">Facebook</option>
<option value="twitter">Twitter</option>
<option value="github">GitHub</option>
<option value="persona">Persona</option>
<option value="google">Google</option>
</select>
</p>
<p data-for="load">
Expand Down
52 changes: 40 additions & 12 deletions my-mind.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ var MM = {
* @class A promise - value to be resolved in the future.
* Implements the "Promises/A+" specification.
*/
var Promise = function() {
var Promise = function(executor) {
this._state = 0; /* 0 = pending, 1 = fulfilled, 2 = rejected */
this._value = null; /* fulfillment / rejection value */

Expand All @@ -60,6 +60,16 @@ var Promise = function() {
}

this._thenPromises = []; /* promises returned by then() */

executor && executor(this.fulfill.bind(this), this.reject.bind(this));
}

Promise.resolve = function(value) {
return new Promise().fulfill(value);
}

Promise.reject = function(value) {
return new Promise().reject(value);
}

/**
Expand Down Expand Up @@ -3382,7 +3392,18 @@ MM.Backend.Firebase = Object.create(MM.Backend, {
});

MM.Backend.Firebase.connect = function(server, auth) {
this.ref = new Firebase("https://" + server + ".firebaseio.com/");
// Initialize Firebase
var config = {
apiKey: "AIzaSyBO_6uCK8pHjoz1c9htVwZi6Skpm8o4LtQ",
authDomain: "my-mind.firebaseapp.com",
databaseURL: "https://" + server + ".firebaseio.com",
projectId: "firebase-my-mind",
storageBucket: "firebase-my-mind.appspot.com",
messagingSenderId: "666556281676"
};
firebase.initializeApp(config);

this.ref = firebase.database().ref();

this.ref.child("names").on("value", function(snap) {
MM.publish("firebase-list", this, snap.val() || {});
Expand Down Expand Up @@ -3553,18 +3574,25 @@ MM.Backend.Firebase._valueChange = function(snap) {
}

MM.Backend.Firebase._login = function(type) {
var promise = new Promise();
var provider;
switch (type) {
case "github":
provider = new firebase.auth.GithubAuthProvider();
break;
case "facebook":
provider = new firebase.auth.FacebookAuthProvider();
break;
case "twitter":
provider = new firebase.auth.TwitterAuthProvider();
break;
case "google":
provider = new firebase.auth.GoogleAuthProvider();
break;
}

var auth = new FirebaseSimpleLogin(this.ref, function(error, user) {
if (error) {
promise.reject(error);
} else if (user) {
promise.fulfill(user);
}
return firebase.auth().signInWithPopup(provider).then(function(result) {
return result.user;
});
auth.login(type);

return promise;
}
MM.Backend.GDrive = Object.create(MM.Backend, {
id: {value: "gdrive"},
Expand Down
40 changes: 29 additions & 11 deletions src/backend.firebase.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,18 @@ MM.Backend.Firebase = Object.create(MM.Backend, {
});

MM.Backend.Firebase.connect = function(server, auth) {
this.ref = new Firebase("https://" + server + ".firebaseio.com/");
// Initialize Firebase
var config = {
apiKey: "AIzaSyBO_6uCK8pHjoz1c9htVwZi6Skpm8o4LtQ",
authDomain: "my-mind.firebaseapp.com",
databaseURL: "https://" + server + ".firebaseio.com",
projectId: "firebase-my-mind",
storageBucket: "firebase-my-mind.appspot.com",
messagingSenderId: "666556281676"
};
firebase.initializeApp(config);

this.ref = firebase.database().ref();

this.ref.child("names").on("value", function(snap) {
MM.publish("firebase-list", this, snap.val() || {});
Expand Down Expand Up @@ -181,16 +192,23 @@ MM.Backend.Firebase._valueChange = function(snap) {
}

MM.Backend.Firebase._login = function(type) {
var promise = new Promise();
var provider;
switch (type) {
case "github":
provider = new firebase.auth.GithubAuthProvider();
break;
case "facebook":
provider = new firebase.auth.FacebookAuthProvider();
break;
case "twitter":
provider = new firebase.auth.TwitterAuthProvider();
break;
case "google":
provider = new firebase.auth.GoogleAuthProvider();
break;
}

var auth = new FirebaseSimpleLogin(this.ref, function(error, user) {
if (error) {
promise.reject(error);
} else if (user) {
promise.fulfill(user);
}
return firebase.auth().signInWithPopup(provider).then(function(result) {
return result.user;
});
auth.login(type);

return promise;
}
12 changes: 11 additions & 1 deletion src/promise.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* @class A promise - value to be resolved in the future.
* Implements the "Promises/A+" specification.
*/
var Promise = function() {
var Promise = function(executor) {
this._state = 0; /* 0 = pending, 1 = fulfilled, 2 = rejected */
this._value = null; /* fulfillment / rejection value */

Expand All @@ -17,6 +17,16 @@ var Promise = function() {
}

this._thenPromises = []; /* promises returned by then() */

executor && executor(this.fulfill.bind(this), this.reject.bind(this));
}

Promise.resolve = function(value) {
return new Promise().fulfill(value);
}

Promise.reject = function(value) {
return new Promise().reject(value);
}

/**
Expand Down

0 comments on commit 9e94038

Please sign in to comment.