Updating text with JavaScript and Firebase
My problem is this causes more lag as time goes on. I use this commonly to chat with my friends, and I need it the site to update in real-time whenever a message gets edited/deleted/added. Any solutions?
function update(){
var i = 0;
var leadsRef = firebase.database().ref(room);
leadsRef.on('value', function(snapshot) {
var old_room = room;
snapshot.forEach(function(childSnapshot) {
var childData = childSnapshot.val();
if(i === 0){
document.getElementById("comments").innerHTML = "";
}
document.getElementById("comments").innerHTML += encode(childData.datee);
document.getElementById("comments").innerHTML += " ";
document.getElementById("comments").innerHTML += encode(childData.namee);
document.getElementById("comments").innerHTML += ": ";
document.getElementById("comments").innerHTML += encode(childData.contentss);
document.getElementById("comments").innerHTML += "<br>";
i += 1
}); i = 0; return 0;
});
}
window.setInterval(update, 100);
The full code can be found here.
javascript performance html5 firebase
New contributor
|
show 12 more comments
My problem is this causes more lag as time goes on. I use this commonly to chat with my friends, and I need it the site to update in real-time whenever a message gets edited/deleted/added. Any solutions?
function update(){
var i = 0;
var leadsRef = firebase.database().ref(room);
leadsRef.on('value', function(snapshot) {
var old_room = room;
snapshot.forEach(function(childSnapshot) {
var childData = childSnapshot.val();
if(i === 0){
document.getElementById("comments").innerHTML = "";
}
document.getElementById("comments").innerHTML += encode(childData.datee);
document.getElementById("comments").innerHTML += " ";
document.getElementById("comments").innerHTML += encode(childData.namee);
document.getElementById("comments").innerHTML += ": ";
document.getElementById("comments").innerHTML += encode(childData.contentss);
document.getElementById("comments").innerHTML += "<br>";
i += 1
}); i = 0; return 0;
});
}
window.setInterval(update, 100);
The full code can be found here.
javascript performance html5 firebase
New contributor
1
What do you mean by "I need it to be real-time."?
– guest271314
13 hours ago
@guest271314 As in the site should update in real-time when somebody types in a message
– MilkyWay90
13 hours ago
Have you tried using a<form>
element, and eitherchange
ofinput
event attached to a<textarea>
or<input type="text">
element, or an<input type="submit">
for the user to press when they want to send a message? Am not certain about whysetInterval
is being used, though should be able to be substituted forrequestAnimationFrame
and logic within the function body. Does the code at the question currently produce the expected result?
– guest271314
13 hours ago
@guest271314 Not sure hwo to do that, could you put the complete code in an answer?
– MilkyWay90
13 hours ago
Have not tried Firebase. Why doesupdate
need to be called every100
milliseconds to re-declareleadsRef
and reattachvalue
event toleadsRef
variable?
– guest271314
13 hours ago
|
show 12 more comments
My problem is this causes more lag as time goes on. I use this commonly to chat with my friends, and I need it the site to update in real-time whenever a message gets edited/deleted/added. Any solutions?
function update(){
var i = 0;
var leadsRef = firebase.database().ref(room);
leadsRef.on('value', function(snapshot) {
var old_room = room;
snapshot.forEach(function(childSnapshot) {
var childData = childSnapshot.val();
if(i === 0){
document.getElementById("comments").innerHTML = "";
}
document.getElementById("comments").innerHTML += encode(childData.datee);
document.getElementById("comments").innerHTML += " ";
document.getElementById("comments").innerHTML += encode(childData.namee);
document.getElementById("comments").innerHTML += ": ";
document.getElementById("comments").innerHTML += encode(childData.contentss);
document.getElementById("comments").innerHTML += "<br>";
i += 1
}); i = 0; return 0;
});
}
window.setInterval(update, 100);
The full code can be found here.
javascript performance html5 firebase
New contributor
My problem is this causes more lag as time goes on. I use this commonly to chat with my friends, and I need it the site to update in real-time whenever a message gets edited/deleted/added. Any solutions?
function update(){
var i = 0;
var leadsRef = firebase.database().ref(room);
leadsRef.on('value', function(snapshot) {
var old_room = room;
snapshot.forEach(function(childSnapshot) {
var childData = childSnapshot.val();
if(i === 0){
document.getElementById("comments").innerHTML = "";
}
document.getElementById("comments").innerHTML += encode(childData.datee);
document.getElementById("comments").innerHTML += " ";
document.getElementById("comments").innerHTML += encode(childData.namee);
document.getElementById("comments").innerHTML += ": ";
document.getElementById("comments").innerHTML += encode(childData.contentss);
document.getElementById("comments").innerHTML += "<br>";
i += 1
}); i = 0; return 0;
});
}
window.setInterval(update, 100);
The full code can be found here.
javascript performance html5 firebase
javascript performance html5 firebase
New contributor
New contributor
edited 25 mins ago
Jamal♦
30.3k11116226
30.3k11116226
New contributor
asked 13 hours ago
MilkyWay90
15
15
New contributor
New contributor
1
What do you mean by "I need it to be real-time."?
– guest271314
13 hours ago
@guest271314 As in the site should update in real-time when somebody types in a message
– MilkyWay90
13 hours ago
Have you tried using a<form>
element, and eitherchange
ofinput
event attached to a<textarea>
or<input type="text">
element, or an<input type="submit">
for the user to press when they want to send a message? Am not certain about whysetInterval
is being used, though should be able to be substituted forrequestAnimationFrame
and logic within the function body. Does the code at the question currently produce the expected result?
– guest271314
13 hours ago
@guest271314 Not sure hwo to do that, could you put the complete code in an answer?
– MilkyWay90
13 hours ago
Have not tried Firebase. Why doesupdate
need to be called every100
milliseconds to re-declareleadsRef
and reattachvalue
event toleadsRef
variable?
– guest271314
13 hours ago
|
show 12 more comments
1
What do you mean by "I need it to be real-time."?
– guest271314
13 hours ago
@guest271314 As in the site should update in real-time when somebody types in a message
– MilkyWay90
13 hours ago
Have you tried using a<form>
element, and eitherchange
ofinput
event attached to a<textarea>
or<input type="text">
element, or an<input type="submit">
for the user to press when they want to send a message? Am not certain about whysetInterval
is being used, though should be able to be substituted forrequestAnimationFrame
and logic within the function body. Does the code at the question currently produce the expected result?
– guest271314
13 hours ago
@guest271314 Not sure hwo to do that, could you put the complete code in an answer?
– MilkyWay90
13 hours ago
Have not tried Firebase. Why doesupdate
need to be called every100
milliseconds to re-declareleadsRef
and reattachvalue
event toleadsRef
variable?
– guest271314
13 hours ago
1
1
What do you mean by "I need it to be real-time."?
– guest271314
13 hours ago
What do you mean by "I need it to be real-time."?
– guest271314
13 hours ago
@guest271314 As in the site should update in real-time when somebody types in a message
– MilkyWay90
13 hours ago
@guest271314 As in the site should update in real-time when somebody types in a message
– MilkyWay90
13 hours ago
Have you tried using a
<form>
element, and either change
of input
event attached to a <textarea>
or <input type="text">
element, or an <input type="submit">
for the user to press when they want to send a message? Am not certain about why setInterval
is being used, though should be able to be substituted for requestAnimationFrame
and logic within the function body. Does the code at the question currently produce the expected result?– guest271314
13 hours ago
Have you tried using a
<form>
element, and either change
of input
event attached to a <textarea>
or <input type="text">
element, or an <input type="submit">
for the user to press when they want to send a message? Am not certain about why setInterval
is being used, though should be able to be substituted for requestAnimationFrame
and logic within the function body. Does the code at the question currently produce the expected result?– guest271314
13 hours ago
@guest271314 Not sure hwo to do that, could you put the complete code in an answer?
– MilkyWay90
13 hours ago
@guest271314 Not sure hwo to do that, could you put the complete code in an answer?
– MilkyWay90
13 hours ago
Have not tried Firebase. Why does
update
need to be called every 100
milliseconds to re-declare leadsRef
and reattach value
event to leadsRef
variable?– guest271314
13 hours ago
Have not tried Firebase. Why does
update
need to be called every 100
milliseconds to re-declare leadsRef
and reattach value
event to leadsRef
variable?– guest271314
13 hours ago
|
show 12 more comments
1 Answer
1
active
oldest
votes
1. Leaking
Between:
window.setInterval(update, 100);
And:
leadsRef.on('value', function(snapshot) {...}
You are adding a new copy of the event handler every 100ms. which just stacks the handle so it runs (time elapsed since page load)/100ms times every time data hits the pipe.
Setting your on('value') handler should fire every time firebase get new data. It's a watcher you've got here not a getter.
2. Redundant Look ups
document.getElementById("comments")
This can be held in a variable and reused rather than finding the element for every stub of text.
3. innerHTML
Setting innerHTML from user input is considered bad practice, use innerText instead. Also build you full string(if possible) and and update all at once, this limits the browser having to re-render the page
4. Data / Output Structure
Each message is an individual item and should be treated as such, showing all the messages into a single p element muddies the distinction and make addressing an individual item difficult if desired
Other/Misc
You should be able to replace the provided code with somthing like this (warning untested, also assumes comments is a div not a p as in the linked code):
firebase.database().ref(room).on('value', function (snapshot) {
var comments = ;
var commentParent = document.getElementById("comments")
snapshot.forEach(function (childSnapshot) {
var childData = childSnapshot.val();
var commentElm = document.createElement("div");
commentElm.setAttribute("class", "comment")
commentElm.innerText = encode(childData.datee) + " " + encode(childData.namee) + ": " + encode(childData.contentss);
comments.push(commentElm)
});
commentParent.innerHTML=''
commentParent.append(...comments)
return 0;
});
Also there is an additional bug with room handling, when changing rooms the handler should be removed and recreated for the new room.
And your linked code pollutes all over the global space >.> not as important since it's not a shared lib but it still rubs me the wrong way.
jsfiddle: https://jsfiddle.net/plloi/fc37pmqa/
Keeps on outputting "[object HTMLDivElement],"
– MilkyWay90
11 hours ago
Missed a spread operator, updated
– Shaun H
11 hours ago
Okay, let me test it
– MilkyWay90
11 hours ago
Okay, that issue is resolved, but now it keeps on outputting the entire script every second
– MilkyWay90
11 hours ago
Like if it said "MW90: hi", it would keep on outputting "MW90: hi" every second. Wait, that just can be fixed by setting document.getElementById("comments") to
– MilkyWay90
11 hours ago
|
show 1 more comment
Your Answer
StackExchange.ifUsing("editor", function () {
return StackExchange.using("mathjaxEditing", function () {
StackExchange.MarkdownEditor.creationCallbacks.add(function (editor, postfix) {
StackExchange.mathjaxEditing.prepareWmdForMathJax(editor, postfix, [["\$", "\$"]]);
});
});
}, "mathjax-editing");
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "196"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
MilkyWay90 is a new contributor. Be nice, and check out our Code of Conduct.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodereview.stackexchange.com%2fquestions%2f210829%2fupdating-text-with-javascript-and-firebase%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
1. Leaking
Between:
window.setInterval(update, 100);
And:
leadsRef.on('value', function(snapshot) {...}
You are adding a new copy of the event handler every 100ms. which just stacks the handle so it runs (time elapsed since page load)/100ms times every time data hits the pipe.
Setting your on('value') handler should fire every time firebase get new data. It's a watcher you've got here not a getter.
2. Redundant Look ups
document.getElementById("comments")
This can be held in a variable and reused rather than finding the element for every stub of text.
3. innerHTML
Setting innerHTML from user input is considered bad practice, use innerText instead. Also build you full string(if possible) and and update all at once, this limits the browser having to re-render the page
4. Data / Output Structure
Each message is an individual item and should be treated as such, showing all the messages into a single p element muddies the distinction and make addressing an individual item difficult if desired
Other/Misc
You should be able to replace the provided code with somthing like this (warning untested, also assumes comments is a div not a p as in the linked code):
firebase.database().ref(room).on('value', function (snapshot) {
var comments = ;
var commentParent = document.getElementById("comments")
snapshot.forEach(function (childSnapshot) {
var childData = childSnapshot.val();
var commentElm = document.createElement("div");
commentElm.setAttribute("class", "comment")
commentElm.innerText = encode(childData.datee) + " " + encode(childData.namee) + ": " + encode(childData.contentss);
comments.push(commentElm)
});
commentParent.innerHTML=''
commentParent.append(...comments)
return 0;
});
Also there is an additional bug with room handling, when changing rooms the handler should be removed and recreated for the new room.
And your linked code pollutes all over the global space >.> not as important since it's not a shared lib but it still rubs me the wrong way.
jsfiddle: https://jsfiddle.net/plloi/fc37pmqa/
Keeps on outputting "[object HTMLDivElement],"
– MilkyWay90
11 hours ago
Missed a spread operator, updated
– Shaun H
11 hours ago
Okay, let me test it
– MilkyWay90
11 hours ago
Okay, that issue is resolved, but now it keeps on outputting the entire script every second
– MilkyWay90
11 hours ago
Like if it said "MW90: hi", it would keep on outputting "MW90: hi" every second. Wait, that just can be fixed by setting document.getElementById("comments") to
– MilkyWay90
11 hours ago
|
show 1 more comment
1. Leaking
Between:
window.setInterval(update, 100);
And:
leadsRef.on('value', function(snapshot) {...}
You are adding a new copy of the event handler every 100ms. which just stacks the handle so it runs (time elapsed since page load)/100ms times every time data hits the pipe.
Setting your on('value') handler should fire every time firebase get new data. It's a watcher you've got here not a getter.
2. Redundant Look ups
document.getElementById("comments")
This can be held in a variable and reused rather than finding the element for every stub of text.
3. innerHTML
Setting innerHTML from user input is considered bad practice, use innerText instead. Also build you full string(if possible) and and update all at once, this limits the browser having to re-render the page
4. Data / Output Structure
Each message is an individual item and should be treated as such, showing all the messages into a single p element muddies the distinction and make addressing an individual item difficult if desired
Other/Misc
You should be able to replace the provided code with somthing like this (warning untested, also assumes comments is a div not a p as in the linked code):
firebase.database().ref(room).on('value', function (snapshot) {
var comments = ;
var commentParent = document.getElementById("comments")
snapshot.forEach(function (childSnapshot) {
var childData = childSnapshot.val();
var commentElm = document.createElement("div");
commentElm.setAttribute("class", "comment")
commentElm.innerText = encode(childData.datee) + " " + encode(childData.namee) + ": " + encode(childData.contentss);
comments.push(commentElm)
});
commentParent.innerHTML=''
commentParent.append(...comments)
return 0;
});
Also there is an additional bug with room handling, when changing rooms the handler should be removed and recreated for the new room.
And your linked code pollutes all over the global space >.> not as important since it's not a shared lib but it still rubs me the wrong way.
jsfiddle: https://jsfiddle.net/plloi/fc37pmqa/
Keeps on outputting "[object HTMLDivElement],"
– MilkyWay90
11 hours ago
Missed a spread operator, updated
– Shaun H
11 hours ago
Okay, let me test it
– MilkyWay90
11 hours ago
Okay, that issue is resolved, but now it keeps on outputting the entire script every second
– MilkyWay90
11 hours ago
Like if it said "MW90: hi", it would keep on outputting "MW90: hi" every second. Wait, that just can be fixed by setting document.getElementById("comments") to
– MilkyWay90
11 hours ago
|
show 1 more comment
1. Leaking
Between:
window.setInterval(update, 100);
And:
leadsRef.on('value', function(snapshot) {...}
You are adding a new copy of the event handler every 100ms. which just stacks the handle so it runs (time elapsed since page load)/100ms times every time data hits the pipe.
Setting your on('value') handler should fire every time firebase get new data. It's a watcher you've got here not a getter.
2. Redundant Look ups
document.getElementById("comments")
This can be held in a variable and reused rather than finding the element for every stub of text.
3. innerHTML
Setting innerHTML from user input is considered bad practice, use innerText instead. Also build you full string(if possible) and and update all at once, this limits the browser having to re-render the page
4. Data / Output Structure
Each message is an individual item and should be treated as such, showing all the messages into a single p element muddies the distinction and make addressing an individual item difficult if desired
Other/Misc
You should be able to replace the provided code with somthing like this (warning untested, also assumes comments is a div not a p as in the linked code):
firebase.database().ref(room).on('value', function (snapshot) {
var comments = ;
var commentParent = document.getElementById("comments")
snapshot.forEach(function (childSnapshot) {
var childData = childSnapshot.val();
var commentElm = document.createElement("div");
commentElm.setAttribute("class", "comment")
commentElm.innerText = encode(childData.datee) + " " + encode(childData.namee) + ": " + encode(childData.contentss);
comments.push(commentElm)
});
commentParent.innerHTML=''
commentParent.append(...comments)
return 0;
});
Also there is an additional bug with room handling, when changing rooms the handler should be removed and recreated for the new room.
And your linked code pollutes all over the global space >.> not as important since it's not a shared lib but it still rubs me the wrong way.
jsfiddle: https://jsfiddle.net/plloi/fc37pmqa/
1. Leaking
Between:
window.setInterval(update, 100);
And:
leadsRef.on('value', function(snapshot) {...}
You are adding a new copy of the event handler every 100ms. which just stacks the handle so it runs (time elapsed since page load)/100ms times every time data hits the pipe.
Setting your on('value') handler should fire every time firebase get new data. It's a watcher you've got here not a getter.
2. Redundant Look ups
document.getElementById("comments")
This can be held in a variable and reused rather than finding the element for every stub of text.
3. innerHTML
Setting innerHTML from user input is considered bad practice, use innerText instead. Also build you full string(if possible) and and update all at once, this limits the browser having to re-render the page
4. Data / Output Structure
Each message is an individual item and should be treated as such, showing all the messages into a single p element muddies the distinction and make addressing an individual item difficult if desired
Other/Misc
You should be able to replace the provided code with somthing like this (warning untested, also assumes comments is a div not a p as in the linked code):
firebase.database().ref(room).on('value', function (snapshot) {
var comments = ;
var commentParent = document.getElementById("comments")
snapshot.forEach(function (childSnapshot) {
var childData = childSnapshot.val();
var commentElm = document.createElement("div");
commentElm.setAttribute("class", "comment")
commentElm.innerText = encode(childData.datee) + " " + encode(childData.namee) + ": " + encode(childData.contentss);
comments.push(commentElm)
});
commentParent.innerHTML=''
commentParent.append(...comments)
return 0;
});
Also there is an additional bug with room handling, when changing rooms the handler should be removed and recreated for the new room.
And your linked code pollutes all over the global space >.> not as important since it's not a shared lib but it still rubs me the wrong way.
jsfiddle: https://jsfiddle.net/plloi/fc37pmqa/
edited 11 hours ago
answered 11 hours ago
Shaun H
49726
49726
Keeps on outputting "[object HTMLDivElement],"
– MilkyWay90
11 hours ago
Missed a spread operator, updated
– Shaun H
11 hours ago
Okay, let me test it
– MilkyWay90
11 hours ago
Okay, that issue is resolved, but now it keeps on outputting the entire script every second
– MilkyWay90
11 hours ago
Like if it said "MW90: hi", it would keep on outputting "MW90: hi" every second. Wait, that just can be fixed by setting document.getElementById("comments") to
– MilkyWay90
11 hours ago
|
show 1 more comment
Keeps on outputting "[object HTMLDivElement],"
– MilkyWay90
11 hours ago
Missed a spread operator, updated
– Shaun H
11 hours ago
Okay, let me test it
– MilkyWay90
11 hours ago
Okay, that issue is resolved, but now it keeps on outputting the entire script every second
– MilkyWay90
11 hours ago
Like if it said "MW90: hi", it would keep on outputting "MW90: hi" every second. Wait, that just can be fixed by setting document.getElementById("comments") to
– MilkyWay90
11 hours ago
Keeps on outputting "[object HTMLDivElement],"
– MilkyWay90
11 hours ago
Keeps on outputting "[object HTMLDivElement],"
– MilkyWay90
11 hours ago
Missed a spread operator, updated
– Shaun H
11 hours ago
Missed a spread operator, updated
– Shaun H
11 hours ago
Okay, let me test it
– MilkyWay90
11 hours ago
Okay, let me test it
– MilkyWay90
11 hours ago
Okay, that issue is resolved, but now it keeps on outputting the entire script every second
– MilkyWay90
11 hours ago
Okay, that issue is resolved, but now it keeps on outputting the entire script every second
– MilkyWay90
11 hours ago
Like if it said "MW90: hi", it would keep on outputting "MW90: hi" every second. Wait, that just can be fixed by setting document.getElementById("comments") to
– MilkyWay90
11 hours ago
Like if it said "MW90: hi", it would keep on outputting "MW90: hi" every second. Wait, that just can be fixed by setting document.getElementById("comments") to
– MilkyWay90
11 hours ago
|
show 1 more comment
MilkyWay90 is a new contributor. Be nice, and check out our Code of Conduct.
MilkyWay90 is a new contributor. Be nice, and check out our Code of Conduct.
MilkyWay90 is a new contributor. Be nice, and check out our Code of Conduct.
MilkyWay90 is a new contributor. Be nice, and check out our Code of Conduct.
Thanks for contributing an answer to Code Review Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
Use MathJax to format equations. MathJax reference.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodereview.stackexchange.com%2fquestions%2f210829%2fupdating-text-with-javascript-and-firebase%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
1
What do you mean by "I need it to be real-time."?
– guest271314
13 hours ago
@guest271314 As in the site should update in real-time when somebody types in a message
– MilkyWay90
13 hours ago
Have you tried using a
<form>
element, and eitherchange
ofinput
event attached to a<textarea>
or<input type="text">
element, or an<input type="submit">
for the user to press when they want to send a message? Am not certain about whysetInterval
is being used, though should be able to be substituted forrequestAnimationFrame
and logic within the function body. Does the code at the question currently produce the expected result?– guest271314
13 hours ago
@guest271314 Not sure hwo to do that, could you put the complete code in an answer?
– MilkyWay90
13 hours ago
Have not tried Firebase. Why does
update
need to be called every100
milliseconds to re-declareleadsRef
and reattachvalue
event toleadsRef
variable?– guest271314
13 hours ago