Navigation Menu

Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

v3 missing firebase.database.ServerValue.TIMESTAMP? #589

Open
oskarrough opened this issue Jul 21, 2019 · 5 comments
Open

v3 missing firebase.database.ServerValue.TIMESTAMP? #589

oskarrough opened this issue Jul 21, 2019 · 5 comments

Comments

@oskarrough
Copy link
Contributor

oskarrough commented Jul 21, 2019

In v2 you could do

import firebase from 'firebase'
firebase.database.ServerValue.TIMESTAMP

but in v3 ServerValue is not defined. What is the right import path? https://firebase.google.com/docs/reference/js/firebase.database.ServerValue.html

I tried accessing database.ServerValue from:

  • import firebase from 'firebase'
  • import firebase from 'firebase/app'
  • firebase: service()
  • firebaseApp: service()
@jamesdaniels
Copy link
Contributor

The proper way is:

import firebase from 'firebase/app';
firebase.database.ServerValue.TIMESTAMP

Note due to an outstanding bug with how the Firebase modules are defined this will throw an error in type-checking. But it's actually correct.

If yu don't care about Node.js support this will work:

import * as firebase from 'firebase/app';
firebase.database.ServerValue.TIMESTAMP

@oskarrough
Copy link
Contributor Author

Thanks, I tried both of your suggestions but I'm seeing this with rc.6?

index.cjs.js:1470 TypeError: Cannot read property 'ServerValue' of undefined
import DS from 'ember-data'
// import firebase from 'firebase/app'
import * as firebase from 'firebase/app'

const {Model, attr, belongsTo, hasMany} = DS

export default Model.extend({
	created: attr('number', {
		defaultValue() {
			return firebase.database.ServerValue.TIMESTAMP
		}
	}),
	channels: hasMany('channel'),
	settings: belongsTo('user-setting')
})

and compiled version

define("xxx/models/user", ["exports", "ember-data", "firebase/app"], function (_exports, _emberData, firebase) {
  "use strict";

  Object.defineProperty(_exports, "__esModule", {
    value: true
  });
  _exports.default = void 0;
  const {
    Model,
    attr,
    belongsTo,
    hasMany
  } = _emberData.default;

  var _default = Model.extend({
    created: attr('number', {
      defaultValue() {
        return firebase.database.ServerValue.TIMESTAMP;
      }

    }),
    channels: hasMany('channel'),
    settings: belongsTo('user-setting')
  });

  _exports.default = _default;
});

@jamesdaniels
Copy link
Contributor

interesting, wonder if auto-import is pruning some dependencies...

@jamesdaniels jamesdaniels reopened this Oct 14, 2019
@jamesdaniels
Copy link
Contributor

I'm planning on adding new data types to the adapter that will do stuff like this for you, I'll leave open for that.

@CICCIOSGAMINO
Copy link

Probably can be close with the Firebase Js V9 API !

  import { serverTimestamp } from 'firebase/database'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants