Services is fully responsible for managing almost everything regarding your data, its interactions, as well as the evolution of information workflow.Understanding that this connects mainly with Firebase data system reliable for storing and syncing data in real time across all connected clients
Retrieve a node from Firebase server.
Retrieve a single resource from the Firebase server.
params.path required
params.listenerType optional
params.eventType optional
response
response.error
FirebaseService.findOne()
is used to
retrieve a model instance from the server.
Use findOne
like:
FirebaseService.findOne({
path: 'posts/post_one',
}, function(response) {
if(!response.error) {
// success
console.log(response);
} else {
// error
console.log(response);
}
});
listenerType: 'once', // 'on','once'
eventType: 'value', // 'value', child_added'
The return response should look like:
{
author: "John Deauthor",
body: "Conveniently harness fictionalized communities high-impact markets under whelm go.",
title: "The post title ", node_id: "post_one"
}
Retrieve multiple nodes from Firebase server.
Retrieve multiple resource from the Firebase server.
params.path required
params.limit required
params.listenerType optional
params.eventType optional
response
response.error
FirebaseService.findAll()
is used to
retrieve a model instance from the server.
Use findAll
like:
FirebaseService.findAll({
path: '/author/posts'
limit: '4'
}, function(response) {
if(!response.error) {
// success
console.log(response);
} else {
// error
console.log(response);
}
});
listenerType: 'once', // 'on','once'
eventType: 'value', // 'value', child_added'
The return data should look like:
{
data: [
{author: "John Deauthor", body: "post body content.", title: "The post title ", node_id: "post_one"},
{author: "John Deauthor", body: "post body content.", title: "Another post title ", node_id: "post_two"},
{author: "John Deauthor", body: "post body content.", title: "Another post title ", node_id: "post_three"},
]
{
Save node to Firebase server.
Retrieve a single resource from the Firebase server.
params.path required
params.data required
-KT-kz68IJrOajjwg865
response.error
saveData
to create an instance. FirebaseService.saveData()
is used to
retrieve a model instance from the server.
If saveData()
is called an instance is created in Firebase.
FirebaseService.saveData({
path: '/author/posts',
data: ({author:"John Deauthor", body: "post body content.", title: "Another post title "})
}, function(data) {
if(!data.error) {
// success
console.log(data);
} else {
// error
console.log(data);
}
});
listenerType: 'once', // 'on','once'
eventType: 'value', // 'value', child_added'
If updateData()
is update the instance created on Firebase base on
the node key in this case . -KT-kz68IJrOajjwg865
FirebaseService.updateData({
path: '/author/posts/-KT-kz68IJrOajjwg865',
data: ({author:"John Deauthor", body: "post body content.", title: "Another post title "})
}, function(data) {
if(!data.error) {
// success
console.log(data);
} else {
// error
console.log(data);
}
});
Delete node from Firebase server.
Destroy resource from the Firebase server.
params.path required
response
response.error
FirebaseService.deleteData()
is used to destroy
resource from the server.
Use deleteData
like:
FirebaseService.deleteData({
path: '/author/posts/-KT-kz68IJrOajjwg865'
}, function(response) {
if(!response.error) {
// success
console.log(response);
} else {
// error
console.log(response);
}
});
If you don't provide a node path with a unique node id, it will delete
the nodes in the json object. Its really important to add the node id
with the params.path
when deleting an instance on the firebase server
Retrieve multiple nodes from Firebase server dynamic query.
Dynamic query to retrieve multiple resource from the Firebase server.
params.query required
params.listenerType optional
params.eventType optional
response
response.error
FirebaseService.customQuery()
is used to
retrieve a model instance from the server.
Use customQuery
like:
FirebaseService.customQuery({
query: firebaseBaseDatabase.ref('author').limitToLast(2).orderByKey(),
}, function(response) {
if(!response.error) {
// success
console.log(response);
} else {
// error
console.log(response);
}
});
listenerType: 'once', // 'on','once'
eventType: 'value', // 'value', child_added'
The return data should look like:
{
data: [
{author: "John Deauthor", body: "post body content.", title: "The post title ", node_id: "post_one"},
{author: "John Deauthor", body: "post body content.", title: "Another post title ", node_id: "post_two"},
]
{
Increment nodes value in the Firebase server.
Dynamic query to retrieve multiple resource from the Firebase server.
params.path required
params.incrementBy (int) required
response
FirebaseService.incrementValue()
is used to
increment a model value instance on the server.
Use incrementValue
like:
FirebaseService.incrementValue({
path: '/author/posts/-KT-kz68IJrOajjwg865/view',
incrementBy: 1
}, function(response) {
if(!response.error) {
// success
console.log(response);
} else {
// error
console.log(response);
}
});
The return data should look like:
incrementValue completed
Retrieve multiple nodes from Firebase server.
Retrieve multiple resource from the Firebase server.
params.path required
params.limit required
params.listenerType optional
params.eventType optional
response
FirebaseService.fileUpload()
is used to upload files instance from
the firebase storage.
Use fileUpload
like:
<input type="file" name="img_src" id="src_input_id">
// returns file in input field
getInputFile('src_input_id');
FirebaseService.fileUpload({
'file': getInputFile('img_src'),
'path': '/author/posts/-KT-kz68IJrOajjwg865/image
}, function (data) {
console.log(data);
if (data.downloadURL) {
// data.downloadURL
}
});
Progress status:
{
progress: 82.1
element: "hklwzqjhguax"
fileName: "hklwzqjhguax.mp3"
fileSize: "1.646 MB"
fileType: "audio/mp3"
}
The return data should look like:
{
downloadURL: "https://firebasestorage.googleapis.com/v0/b/app-gen.appspot.com/o/-KXeLTodVdfAcMNTmVVr%2F-KaGf2Y2jJO9h_p_49g_0Skitmp3.extention"
element: "hklwzqjhguax"
fileName: "hklwzqjhguax.mp3"
fileSize: "1.646 MB"
fileType: "audio/mp3"
}
The most important parts of the Swallow.Js Framework are the simple included set of different functions. Swallow.Js is built on these components PathJs for routing, MustacheJs for view and depend more on Firebase for data-source, and also build-in server side request for your regular JSON calls.