Skip to content

Commit

Permalink
refactor(build): use object style author
Browse files Browse the repository at this point in the history
  • Loading branch information
posva committed Apr 15, 2018
1 parent 8f462b1 commit 515b68e
Show file tree
Hide file tree
Showing 4 changed files with 190 additions and 134 deletions.
2 changes: 1 addition & 1 deletion build/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const packageData = require('../package.json')
const mkdirp = require('mkdirp')
const { version, author, name } = packageData
// remove the email at the end
const authorName = author.replace(/\s+<.*/, '')
const authorName = author.name
const moduleName = 'Vuefire'

// Make sure dist dir exists
Expand Down
198 changes: 97 additions & 101 deletions examples/index.html
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>VueFire Todo App Demo</title>
<script src="https://www.gstatic.com/firebasejs/4.6.0/firebase.js"></script>
<script src="https://www.gstatic.com/firebasejs/4.6.0/firebase-firestore.js"></script>
<script src="https://unpkg.com/vue"></script>
<script src="../dist/vuefire.js"></script>
</head>
<body>

<!--

<head>
<meta charset="utf-8">
<title>VueFire Todo App Demo</title>
<script src="https://www.gstatic.com/firebasejs/4.6.0/firebase.js"></script>
<script src="https://www.gstatic.com/firebasejs/4.6.0/firebase-firestore.js"></script>
<script src="https://unpkg.com/vue"></script>
<script src="../dist/vuefire.js"></script>
</head>

<body>

<!--
Before running this example, make sure to:
1. cd path/to/vuefire
Expand All @@ -25,100 +27,94 @@
https://jsfiddle.net/posva/wtyop5jy/
-->

<div id="app">
<button @click="toggleTodos">Toggle todos</button>
<br/>
<input
v-model.trim="newTodoText"
@keyup.enter="addTodo"
placeholder="Add new todo"
>
<ul>
<li v-for="todo in todos">
<input
:value="todo.text"
@input="updateTodoText(todo, $event.target.value)"
>
<button @click="removeTodo(todo)">X</button>
</li>
</ul>

<h4>collection with refs</h4>

<ul>
<li v-for="moment in moments">{{ moment }}</li>
</ul>

<h5>Original data</h5>

<ul>
<li v-for="tweet in tweets">{{ tweet }}</li>
</ul>

<p>config: </p>
<pre>
<div id="app">
<button @click="toggleTodos">Toggle todos</button>
<br/>
<input v-model.trim="newTodoText" @keyup.enter="addTodo" placeholder="Add new todo">
<ul>
<li v-for="todo in todos">
<input :value="todo.text" @input="updateTodoText(todo, $event.target.value)">
<button @click="removeTodo(todo)">X</button>
</li>
</ul>

<h4>collection with refs</h4>

<ul>
<li v-for="moment in moments">{{ moment }}</li>
</ul>

<h5>Original data</h5>

<ul>
<li v-for="tweet in tweets">{{ tweet }}</li>
</ul>

<p>config: </p>
<pre>
{{ config }}
</pre>
</div>

<script>
/* global Vue, firebase, Vuefire */
Vue.use(Vuefire.default)
firebase.initializeApp({
projectId: 'vue-fire-store',
databaseURL: 'https://vue-fire-store.firebaseio.com'
})
const db = firebase.firestore()
const todos = db.collection('todos')
const unFinishedTodos = todos.where('finished', '==', false)
const finishedTodos = todos.where('finished', '==', true)
const config = db.collection('configs').doc('jORwjIykFo2NmkdzTkhU')

new Vue({
el: '#app',
data: {
todos: [],
tweets: [],
moments: [],
config: null,
newTodoText: ''
},
</div>

firestore: {
todos: unFinishedTodos,
moments: db.collection('moments'),
tweets: db.collection('tweets'),
config
},
<script>
/* global Vue, firebase, Vuefire */
Vue.use(Vuefire)
firebase.initializeApp({
projectId: 'vue-fire-store',
databaseURL: 'https://vue-fire-store.firebaseio.com'
})
const db = firebase.firestore()
const todos = db.collection('todos')
const unFinishedTodos = todos.where('finished', '==', false)
const finishedTodos = todos.where('finished', '==', true)
const config = db.collection('configs').doc('jORwjIykFo2NmkdzTkhU')

new Vue({
el: '#app',
data: {
todos: [],
tweets: [],
moments: [],
config: null,
newTodoText: ''
},

firestore: {
todos: unFinishedTodos,
moments: db.collection('moments'),
tweets: db.collection('tweets'),
config
},

methods: {
addTodo: function () {
if (this.newTodoText) {
todos.add({
finished: false,
text: this.newTodoText,
created: firebase.firestore.FieldValue.serverTimestamp()
})
this.newTodoText = ''
}
},
updateTodoText: function (todo, newText) {
todos.doc(todo.id).update({ text: newText })
},
removeTodo: function (todo) {
todos.doc(todo.id).delete()
},
toggleTodos () {
console.log(this.$firestoreRefs.todos === unFinishedTodos)
this.$bind(
'todos',
this.$firestoreRefs.todos === unFinishedTodos
? finishedTodos
: unFinishedTodos
)
methods: {
addTodo: function () {
if (this.newTodoText) {
todos.add({
finished: false,
text: this.newTodoText,
created: firebase.firestore.FieldValue.serverTimestamp()
})
this.newTodoText = ''
}
},
updateTodoText: function (todo, newText) {
todos.doc(todo.id).update({ text: newText })
},
removeTodo: function (todo) {
todos.doc(todo.id).delete()
},
toggleTodos: function () {
console.log(this.$firestoreRefs.todos === unFinishedTodos)
this.$bind(
'todos',
this.$firestoreRefs.todos === unFinishedTodos
? finishedTodos
: unFinishedTodos
)
}
})
</script>
</body>
}
})
</script>
</body>

</html>

0 comments on commit 515b68e

Please sign in to comment.