Skip to content

Commit

Permalink
create firebase document component
Browse files Browse the repository at this point in the history
  • Loading branch information
nigeltiany committed Jul 23, 2017
1 parent d479ccb commit 5a593b7
Show file tree
Hide file tree
Showing 5 changed files with 264 additions and 3 deletions.
216 changes: 216 additions & 0 deletions dist/vuefire.js
Original file line number Diff line number Diff line change
Expand Up @@ -3510,6 +3510,10 @@ var _firebase = __webpack_require__(29);

var _firebase2 = _interopRequireDefault(_firebase);

var _firebaseDocument = __webpack_require__(60);

var _firebaseDocument2 = _interopRequireDefault(_firebaseDocument);

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
Expand Down Expand Up @@ -3587,6 +3591,8 @@ exports.default = {

var firebaseApp = new FirebaseApp(project);
Vue.prototype.$firebase = firebaseApp;

Vue.component('firebase-document', _firebaseDocument2.default);
}
};

Expand Down Expand Up @@ -8989,6 +8995,216 @@ module.exports = exports['default'];
//# sourceMappingURL=sw-controller.js.map


/***/ }),
/* 60 */
/***/ (function(module, __webpack_exports__, __webpack_require__) {

"use strict";
Object.defineProperty(__webpack_exports__, "__esModule", { value: true });
/* harmony import */ var __WEBPACK_IMPORTED_MODULE_0__babel_loader_node_modules_vue_loader_lib_selector_type_script_index_0_firebase_document_vue__ = __webpack_require__(62);
/* harmony import */ var __WEBPACK_IMPORTED_MODULE_1__node_modules_vue_loader_lib_template_compiler_index_id_data_v_7267e2d4_node_modules_vue_loader_lib_selector_type_template_index_0_firebase_document_vue__ = __webpack_require__(63);
var disposed = false
var normalizeComponent = __webpack_require__(61)
/* script */

/* template */

/* styles */
var __vue_styles__ = null
/* scopeId */
var __vue_scopeId__ = null
/* moduleIdentifier (server only) */
var __vue_module_identifier__ = null
var Component = normalizeComponent(
__WEBPACK_IMPORTED_MODULE_0__babel_loader_node_modules_vue_loader_lib_selector_type_script_index_0_firebase_document_vue__["a" /* default */],
__WEBPACK_IMPORTED_MODULE_1__node_modules_vue_loader_lib_template_compiler_index_id_data_v_7267e2d4_node_modules_vue_loader_lib_selector_type_template_index_0_firebase_document_vue__["a" /* default */],
__vue_styles__,
__vue_scopeId__,
__vue_module_identifier__
)
Component.options.__file = "src/components/firebase-document.vue"
if (Component.esModule && Object.keys(Component.esModule).some(function (key) {return key !== "default" && key.substr(0, 2) !== "__"})) {console.error("named exports are not supported in *.vue files.")}
if (Component.options.functional) {console.error("[vue-loader] firebase-document.vue: functional components are not supported with templates, they should use render functions.")}

/* hot reload */
if (false) {(function () {
var hotAPI = require("vue-hot-reload-api")
hotAPI.install(require("vue"), false)
if (!hotAPI.compatible) return
module.hot.accept()
if (!module.hot.data) {
hotAPI.createRecord("data-v-7267e2d4", Component.options)
} else {
hotAPI.reload("data-v-7267e2d4", Component.options)
}
module.hot.dispose(function (data) {
disposed = true
})
})()}

/* harmony default export */ __webpack_exports__["default"] = (Component.exports);


/***/ }),
/* 61 */
/***/ (function(module, exports) {

/* globals __VUE_SSR_CONTEXT__ */

// this module is a runtime utility for cleaner component module output and will
// be included in the final webpack user bundle

module.exports = function normalizeComponent (
rawScriptExports,
compiledTemplate,
injectStyles,
scopeId,
moduleIdentifier /* server only */
) {
var esModule
var scriptExports = rawScriptExports = rawScriptExports || {}

// ES6 modules interop
var type = typeof rawScriptExports.default
if (type === 'object' || type === 'function') {
esModule = rawScriptExports
scriptExports = rawScriptExports.default
}

// Vue.extend constructor export interop
var options = typeof scriptExports === 'function'
? scriptExports.options
: scriptExports

// render functions
if (compiledTemplate) {
options.render = compiledTemplate.render
options.staticRenderFns = compiledTemplate.staticRenderFns
}

// scopedId
if (scopeId) {
options._scopeId = scopeId
}

var hook
if (moduleIdentifier) { // server build
hook = function (context) {
// 2.3 injection
context =
context || // cached call
(this.$vnode && this.$vnode.ssrContext) || // stateful
(this.parent && this.parent.$vnode && this.parent.$vnode.ssrContext) // functional
// 2.2 with runInNewContext: true
if (!context && typeof __VUE_SSR_CONTEXT__ !== 'undefined') {
context = __VUE_SSR_CONTEXT__
}
// inject component styles
if (injectStyles) {
injectStyles.call(this, context)
}
// register component module identifier for async chunk inferrence
if (context && context._registeredComponents) {
context._registeredComponents.add(moduleIdentifier)
}
}
// used by ssr in case component is cached and beforeCreate
// never gets called
options._ssrRegister = hook
} else if (injectStyles) {
hook = injectStyles
}

if (hook) {
var functional = options.functional
var existing = functional
? options.render
: options.beforeCreate
if (!functional) {
// inject component registration as beforeCreate hook
options.beforeCreate = existing
? [].concat(existing, hook)
: [hook]
} else {
// register for functioal component in vue file
options.render = function renderWithStyleInjection (h, context) {
hook.call(context)
return existing(h, context)
}
}
}

return {
esModule: esModule,
exports: scriptExports,
options: options
}
}


/***/ }),
/* 62 */
/***/ (function(module, __webpack_exports__, __webpack_require__) {

"use strict";
//


/* harmony default export */ __webpack_exports__["a"] = ({
props: {
path: {
type: String,
required: true
},
data: {
type: [String, Object, Number, Function]
},
once: {
type: Boolean,
required: false,
value: false
}
},
created() {
this.fetchData();
},
methods: {
fetchData() {
this.$firebase.database().ref(this.path)[this.once ? 'once' : 'on']('value', snapshot => {
if (typeof this.data === 'function') {
this.data(snapshot);
} else {
this.data = snapshot;
}
});
}
},
watch: {
path() {
this.fetchData();
}
}
});

/***/ }),
/* 63 */
/***/ (function(module, __webpack_exports__, __webpack_require__) {

"use strict";
var render = function () {var _vm=this;var _h=_vm.$createElement;var _c=_vm._self._c||_h;
return _c("div")
}
var staticRenderFns = []
render._withStripped = true
var esExports = { render: render, staticRenderFns: staticRenderFns }
/* harmony default export */ __webpack_exports__["a"] = (esExports);
if (false) {
module.hot.accept()
if (module.hot.data) {
require("vue-hot-reload-api").rerender("data-v-7267e2d4", esExports)
}
}

/***/ })
/******/ ]);
});
Expand Down
2 changes: 1 addition & 1 deletion dist/vuefire.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@vuefire/vuefire",
"version": "0.0.1",
"version": "0.0.2",
"description": "Firebase for vuejs",
"main": "dist/vuefire.js",
"scripts": {
Expand Down
41 changes: 41 additions & 0 deletions src/components/firebase-document.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<template></template>
<script>
export default {
props: {
path: {
type: String,
required: true
},
data: {
type: [String, Object, Number, Function]
},
once: {
type: Boolean,
required: false,
value: false
}
},
created () {
this.fetchData()
},
methods: {
fetchData () {
this.$firebase.database().ref(this.path)[this.once ? 'once' : 'on']('value', (snapshot) => {
if (typeof this.data === 'function') {
this.data(snapshot)
}
else {
this.data = snapshot
}
})
}
},
watch: {
path () {
this.fetchData()
}
}
}
</script>
6 changes: 5 additions & 1 deletion src/vuefire.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import Firebase from 'firebase'
import FirebaseDocument from './components/firebase-document.vue'

export default {
install(Vue, { project, vuex, mixins = [] }) {
Expand Down Expand Up @@ -66,6 +67,9 @@ export default {

const firebaseApp = new FirebaseApp(project)
Vue.prototype.$firebase = firebaseApp

Vue.component('firebase-document', FirebaseDocument)

}
}

Expand All @@ -79,4 +83,4 @@ class FirebaseApp extends Mixins {
this.database = Firebase.database
}

}
}

0 comments on commit 5a593b7

Please sign in to comment.