firebase: update

This commit is contained in:
Rico Sta. Cruz 2017-08-30 21:29:08 +08:00
parent 1a1001e5e2
commit f322e04cf2
No known key found for this signature in database
GPG Key ID: CAAD38AE2962619A
4 changed files with 71 additions and 49 deletions

View File

@ -41,13 +41,17 @@ layout: 2017/sheet # 'default' | '2017/sheet'
# Optional:
updated: 2017-08-30 # To show in the updated list
ads: false # Add this to disable ads
weight: -5 # lower number = higher in related posts list
deprecated: true # Don't show in related posts
prism_languages: [vim] # Extra syntax highlighting
ads: false # Add this to disable ads
weight: -5 # lower number = higher in related posts list
deprecated: true # Don't show in related posts
prism_languages: [vim] # Extra syntax highlighting
---
```
For supported prism languages:
- <https://github.com/PrismJS/prism/tree/gh-pages/components>
## Setting up redirects
This example sets up a redirect from `es2015` to `es6`:

View File

@ -36,6 +36,12 @@ defaults:
type: article
category: "Others"
excerpt_separator: "<!--more-->"
prism_languages:
- jsx
- bash
- scss
- elixir
- ruby
# Site info
url: http://ricostacruz.com/cheatsheets

View File

@ -8,11 +8,6 @@
<script src='https://code.jquery.com/jquery-3.1.0.js'></script>
<script src='https://unpkg.com/isotope-layout@3.0.4/dist/isotope.pkgd.min.js'></script>
<script src='https://unpkg.com/prismjs@1.6.0'></script>
<script src='https://unpkg.com/prismjs@1.6.0/components/prism-jsx.min.js'></script>
<script src='https://unpkg.com/prismjs@1.6.0/components/prism-bash.min.js'></script>
<script src='https://unpkg.com/prismjs@1.6.0/components/prism-scss.min.js'></script>
<script src='https://unpkg.com/prismjs@1.6.0/components/prism-elixir.min.js'></script>
<script src='https://unpkg.com/prismjs@1.6.0/components/prism-ruby.min.js'></script>
{% for lang in page.prism_languages %}
<script src='https://unpkg.com/prismjs@1.6.0/components/prism-{{lang}}.min.js'></script>
{% endfor %}

View File

@ -1,71 +1,88 @@
---
title: Firebase
prism_languages: [coffeescript]
tags: [WIP]
layout: 2017/sheet
---
wip
### Authenticating
### Starting
``` coffee
Fb = new Firebase('https://xxx.firebase.io')
Fb.auth(TOKEN, (err, result) -> ...)
.authAnonymously(...)
.authWithPassword(...)
.authWithOAuthPopup(...)
.authWithOAuthToken(...)
```js
FB = new Firebase('https://xxx.firebase.io')
FB.auth(TOKEN, (err, result) => { ···})
```
### Updating values
```js
FB.authAnonymously(···)
FB.authWithPassword(···)
FB.authWithOAuthPopup(···)
FB.authWithOAuthToken(···)
```
``` coffee
Users = Fb.child('users')
### Using
# create
user = Users.push(first: "Frank", last: "Sinatra")
```js
Users = FB.child('users')
```
# retrieve
user = Users.child('alan') # gets `users/alan`
```js
// Create
user = Users.push(first: "Frank", last: "Sinatra")
```
# setting
user
.set(first: "Miles", last: "Davis")
.update(first: "Miles")
.setWithPriority({ ... }, priority)
```js
// Retrieve
user = Users.child('alan') // gets `users/alan`
```
```js
// Update
user.set(first: "Miles", last: "Davis")
user.update(first: "Miles")
user.setWithPriority({ ··· }, priority)
```
# destroy
user.remove()
```js
// Destroy
user.remove()
```
# getting
user.name() # primary id
```js
// Getting
user.name() // primary id
user.once 'value', (snap) ->
snap.name() # primary id
snap.val() # value
, (err) ->
user.once('value', (snap) => {
snap.name() // primary id
snap.val() // value
}, (err) => {
···
})
```
# traversal
user.parent()
```js
// traversal
user.parent()
```
### Querying
```coffee
Users = Fb.child('users')
```coffeescript
Users = FB.child('users')
Users
.startAt(1000)
.limit(50)
.equalTo(priority, [name])
.on 'child_added', (snap) -> ...
.on 'child_added', (snap) -> ···
```
### Lists
```coffee
Posts = Fb.child('posts')
```coffeescript
Posts = FB.child('posts')
post = Posts.push({ title: "How to do things", author: "alan" })
```
### References
## References
{: .-one-column}
* https://www.firebase.com/docs/web/api/
* https://www.firebase.com/docs/web/recipes.html
* <https://www.firebase.com/docs/web/api/>
* <https://www.firebase.com/docs/web/recipes.html>