Skip to content

Commit f8361a0

Browse files
committed
update firebase example (close #1110)
1 parent 336471f commit f8361a0

File tree

3 files changed

+23
-38
lines changed

3 files changed

+23
-38
lines changed

examples/firebase/app.js

Lines changed: 16 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,12 @@ var Users = new Firebase(baseURL + 'users')
99

1010
Users.on('child_added', function (snapshot) {
1111
var item = snapshot.val()
12-
item.id = snapshot.name()
12+
item.id = snapshot.key()
1313
app.users.push(item)
1414
})
1515

1616
Users.on('child_removed', function (snapshot) {
17-
var id = snapshot.name()
17+
var id = snapshot.key()
1818
app.users.some(function (user) {
1919
if (user.id === id) {
2020
app.users.$remove(user)
@@ -38,56 +38,37 @@ var app = new Vue({
3838
newUser: {
3939
name: '',
4040
email: ''
41-
},
42-
validation: {
43-
name: false,
44-
email: false
45-
}
46-
},
47-
48-
// validation filters are "write only" filters
49-
filters: {
50-
nameValidator: {
51-
write: function (val) {
52-
this.validation.name = !!val
53-
return val
54-
}
55-
},
56-
emailValidator: {
57-
write: function (val) {
58-
this.validation.email = emailRE.test(val)
59-
return val
60-
}
6141
}
6242
},
6343

6444
// computed property for form validation state
6545
computed: {
66-
isValid: function () {
67-
var valid = true
68-
for (var key in this.validation) {
69-
if (!this.validation[key]) {
70-
valid = false
71-
}
46+
validation: function () {
47+
return {
48+
name: !!this.newUser.name.trim(),
49+
email: emailRE.test(this.newUser.email)
7250
}
73-
return valid
51+
},
52+
isValid: function () {
53+
var validation = this.validation
54+
return Object.keys(validation).every(function (key) {
55+
return validation[key]
56+
})
7457
}
7558
},
76-
59+
7760
// methods
7861
methods: {
7962
addUser: function (e) {
8063
e.preventDefault()
8164
if (this.isValid) {
8265
Users.push(this.newUser)
83-
this.newUser = {
84-
name: '',
85-
email: ''
86-
}
66+
this.newUser.name = ''
67+
this.newUser.email = ''
8768
}
8869
},
8970
removeUser: function (user) {
9071
new Firebase(baseURL + 'users/' + user.id).remove()
9172
}
9273
}
93-
})
74+
})

examples/firebase/index.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@
1616
</li>
1717
</ul>
1818
<form id="form" v-on="submit:addUser">
19-
<input v-model="newUser.name | nameValidator | capitalize">
20-
<input v-model="newUser.email | emailValidator">
19+
<input v-model="newUser.name">
20+
<input v-model="newUser.email">
2121
<input type="submit" value="Add User">
2222
</form>
2323
<ul class="errors">

examples/firebase/style.css

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
body {
2+
font-family: Helvetica, Arial, sans-serif;
3+
}
4+
15
ul {
26
padding: 0;
37
}
@@ -25,4 +29,4 @@ ul {
2529

2630
.errors {
2731
color: #f00;
28-
}
32+
}

0 commit comments

Comments
 (0)