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

Example with Firebase 3.9 #18

Open
wants to merge 1 commit into
base: effect-manager
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
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
31 changes: 22 additions & 9 deletions example/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,28 @@
<title>ElmFire Example</title>
</head>
<body>
<div id="main"></div>
<script src="https://cdn.firebase.com/js/client/2.4.2/firebase.js"></script>
<script src="build/elm.js"></script>
<script>
var node = document.getElementById('main');
var app = Elm.Main.embed(node);
</script>
</body>
</html>
<div id="main"></div>

<script src="https://www.gstatic.com/firebasejs/3.9.0/firebase.js"></script>
<script>
// Initialize Firebase
var config = {
apiKey: "AIzaSyBYA5qGnTsJqwIqIsvNB1Ymth2ldfc0lVo",
authDomain: "p-7dae7.firebaseapp.com",
databaseURL: "https://p-7dae7.firebaseio.com",
projectId: "p-7dae7",
storageBucket: "p-7dae7.appspot.com",
messagingSenderId: "588903335427"
};
firebase.initializeApp(config);
</script>

<script src="build/elm.js"></script>
<script>
// Initialize ELM
var node = document.getElementById('main');
var app = Elm.Main.embed(node);
</script>

</body>
</html>
2 changes: 1 addition & 1 deletion example/src/Example.elm
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ import ElmFire

firebaseUrl : String
firebaseUrl =
"https://elmfiretest.firebaseio.com/example"
"https://p-7dae7.firebaseio.com/test"


main : Program Never Model Msg
Expand Down
15 changes: 10 additions & 5 deletions src/Native/ElmFire.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ var _ThomasWeiser$elmfire$Native_ElmFire = function () {

var pleaseReportThis = ' Should not happen, please report this as a bug in ElmFire!';


// Get a reference to the database service
var database = firebase.database();


function asMaybe (value) {
if (typeof value === 'undefined' || value === null) {
return { ctor: 'Nothing' };
Expand Down Expand Up @@ -82,7 +87,7 @@ var _ThomasWeiser$elmfire$Native_ElmFire = function () {
var rest = locationList._1;
switch (head._0) {
case 'url':
ref = new Firebase (head._1);
ref = database.refFromURL(head._1)
break;
case 'child':
ref = getRefStep (rest) .child (head._1);
Expand Down Expand Up @@ -122,7 +127,7 @@ var _ThomasWeiser$elmfire$Native_ElmFire = function () {
}

function key (reference) {
var res = reference .key ();
var res = reference.key;
if (res === null) {
res = '';
}
Expand Down Expand Up @@ -358,15 +363,15 @@ var _ThomasWeiser$elmfire$Native_ElmFire = function () {
}

function snapshot2elm (subscription, fbSnapshot, prevKey) {
var key = fbSnapshot .key ();
var key = fbSnapshot .key;
if (key === null) {
key = '';
}
var value = fbSnapshot .val ();
return {
subscription: subscription,
key: key,
reference: fbSnapshot .ref (),
reference: fbSnapshot .ref,
existing: value !== null,
value: value,
prevKey: asMaybe (prevKey),
Expand Down Expand Up @@ -507,7 +512,7 @@ var _ThomasWeiser$elmfire$Native_ElmFire = function () {
});
}

var serverTimeStamp = Firebase.ServerValue.TIMESTAMP;
var serverTimeStamp = firebase.database.ServerValue.TIMESTAMP;

return {
// Values exported to Elm
Expand Down