Coder Social home page Coder Social logo

zenginehq / zn-backend-firebase Goto Github PK

View Code? Open in Web Editor NEW
0.0 10.0 3.0 605 KB

Helper module for working with znFirebase in Zengine backend plugins.

Home Page: https://zenginehq.github.io/zn-backend-firebase

License: MIT License

JavaScript 100.00%

zn-backend-firebase's Introduction

Backend Firebase

Helper module for working with znFirebase in Zengine backend Plugins.

Coverage Status Build Status npm version

Installation

npm i @zenginehq/backend-firebase --save

Usage

var $firebase = require('@zenginehq/backend-firebase')();

var workspaceId = 11111;

// Load data.
$firebase.load(workspaceId).then(function (data) {
  console.log('it works!', data);
  // data fetched from <firebaseRoot>/11111
}).catch(function (err) {
  console.error(err);
});

// Save data.
var dataObj = {
  'childRoute': someData
  // someData could be any data type,
  // but dataObj (2nd argument of .save()) must be an object
}

$firebase.save(workspaceId, dataObj).then(function () {
  console.log('success!');
  // someData was saved at <firebaseRoot>/11111/childRoute
}).catch(function (err) {
  console.error(err);
});

// Delete data.
var recordId = 222
var deleteObj = {}
deleteObj[recordId] = null

$firebase.save(workspaceId, deleteObj).then(function () {
  console.log('success!');
  // the firebase route <firebaseRoot>/11111/222
  // and all data it contained has been deleted
}).catch(function (err) {
  console.error(err);
})

// Use arrays to formulate complex Firebase paths for both loading and saving.
var formId = 222
var recordId = 333

$firebase.load([workspaceId, formId, recordId, 'settings']).then(function (data) {
  // This will expand to: <firebaseRoot>/11111/222/333/settings
  console.log('it works!', data);
}).catch(function (err) {
  console.error(err);
});

// You can also pass a long string if that's your thing.
$firebase.load('foo/bar/baz/' + workspaceId + '/etc');

Note about Deletions

Passing null as the second argument of .save will cause strange and unhelpful behavior. Instead, pass an object with the endpoint(s) as the key(s) and null as the value(s) for the second argument. See Firebase docs for the underlying .update() command that is called.

Ex:

// much regrets
$firebase.save([workspaceId, 'undesiredField'], null).then(function () {
  //etc...
})

// all the good vibes
$firebase.save(workspaceId, {'undesiredField': null}).then(function () {
  // great work, team!
});

Contributing

See contributing doc

API Docs

Full documentation

zn-backend-firebase's People

Contributors

tehpsalmist avatar aparks avatar evert0n avatar dependabot[bot] avatar

Watchers

Ted Kulp avatar Anthony Putignano avatar  avatar James Cloos avatar David McNelis avatar  avatar  avatar Juan Scarton avatar  avatar Joe avatar

zn-backend-firebase's Issues

Silent Error/hang for .save()

I have had this experience a few times during development, where my save configuration isn't perfect (like passing null as second argument, for example), and instead of returning an error, it just silently hangs my backend service. As long as I passed the proper params, it would execute and return just fine, but I couldn't catch any errors. I can look into this in more detail to see what's wrong with the source code, but in the meantime I'll leave this issue here in case anyone else has an idea why that would (not) happen.

Breaking Change with Module API

The previous module API no longer works because of the way the methods are defined. Either the docs or the code should be updated.

Previous:
$firebase.load(workspaceId)

Current:
$firebase().load(workspaceId)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.