0.0.23 • Published 6 years ago

firestruct v0.0.23

Weekly downloads
3
License
MIT
Repository
github
Last release
6 years ago

Firestruct

Install:

npm install firestruct

Usage:

import Firestruct from "firestruct";

const count = c => c.value();
const increment = c => c.update(i => i + 1);

const fs = new Firestruct("https://test.firebaseio.com/clickcount");

fs.on("swap", (newCursor, oldCursor, path) => {
    const clicksCursor = newCursor.cursor("clicks");

    React.render(
        <ClickCount
            count={ count(clicksCursor) }
            onClick={ event => increment(clicksCursor) } />,
        document.body
    );
);

API:

Structure

on(eventName, callback)

Event handler. Provides callback with 3 arguments:

  • newCursor
  • oldCursor
  • changePath TODO

Events:

  • "swap": data change

structure._fb

Deprecated. Reference to raw Firebase object.

Please make note of any use; it should be unnecessary for all but Auth.

Cursor

Cursors are immutable references to the current structure.

cursor.cursor(path)

Returns a new cursor.

path is an array/string pointing to a child location.

cursor.value()

Returns the value of the current cursor

cursor.update(callback)

Replaces the value of the current cursor with the return value of callback. TODO: Returns the new cursor.

callback is provided with the current value of the cursor as the first argument.

  • New branches may be created by selecting a non-existant path, then calling update with some data.

  • Old branches may be deleted by selecting a path, then setting it as undefined.

cursor.cursors()

Convenience function. Returns an array of child [key, cursor] pairs.

cursor._fb

Deprecated. Reference to raw Firebase snapshot.

Please make note of any use; it should be unnecessary. Tree-climbing and current node keys will never be supported.

0.0.23

6 years ago

0.0.23-beta0

6 years ago

0.0.22

7 years ago

0.0.21

7 years ago

0.0.20

8 years ago

0.0.19

8 years ago

0.0.18

8 years ago

0.0.17

9 years ago

0.0.16

9 years ago

0.0.15

9 years ago

0.0.14

9 years ago

0.0.13

9 years ago

0.0.12

9 years ago

0.0.11

9 years ago

0.0.10

9 years ago

0.0.9

9 years ago

0.0.8

9 years ago

0.0.7

9 years ago

0.0.6

9 years ago

0.0.5

9 years ago

0.0.4

9 years ago

0.0.3

9 years ago

0.0.2

9 years ago

0.0.1

9 years ago

0.0.0

9 years ago