Update
This commit is contained in:
parent
1e78ce422b
commit
9b84703c36
|
@ -77,6 +77,14 @@ $(function () {
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Helper for splitting to words
|
||||||
|
*/
|
||||||
|
|
||||||
|
function splitwords (str) {
|
||||||
|
return str.toLowerCase().split(/[ \/\-_]/)
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Search
|
* Search
|
||||||
*/
|
*/
|
||||||
|
@ -87,7 +95,7 @@ const Search = {
|
||||||
},
|
},
|
||||||
|
|
||||||
show (val) {
|
show (val) {
|
||||||
const keywords = val.split(/[ \-_]/)
|
const keywords = splitwords(val)
|
||||||
const selectors = keywords
|
const selectors = keywords
|
||||||
.map(k => `[data-search-index~=${JSON.stringify(k)}]`)
|
.map(k => `[data-search-index~=${JSON.stringify(k)}]`)
|
||||||
.join('')
|
.join('')
|
||||||
|
@ -114,7 +122,7 @@ function permutate (data) {
|
||||||
|
|
||||||
function permutateString (str) {
|
function permutateString (str) {
|
||||||
let words = []
|
let words = []
|
||||||
let inputs = str.toLowerCase().split(/[ \-_]/)
|
let inputs = splitwords(str)
|
||||||
inputs.forEach(word => {
|
inputs.forEach(word => {
|
||||||
words = words.concat(permutateWord(word))
|
words = words.concat(permutateWord(word))
|
||||||
})
|
})
|
||||||
|
|
76
js-model.md
76
js-model.md
|
@ -1,9 +1,13 @@
|
||||||
---
|
---
|
||||||
title: js-model
|
title: js-model
|
||||||
category: JavaScript libraries
|
category: JavaScript libraries
|
||||||
|
layout: 2017/sheet
|
||||||
---
|
---
|
||||||
|
|
||||||
Project = Model "project", ->
|
### Example
|
||||||
|
|
||||||
|
```bash
|
||||||
|
Project = Model "project", ->
|
||||||
@extend
|
@extend
|
||||||
findByTitle: (title) -> ...
|
findByTitle: (title) -> ...
|
||||||
|
|
||||||
|
@ -11,50 +15,72 @@ category: JavaScript libraries
|
||||||
markAsDone: -> ...
|
markAsDone: -> ...
|
||||||
|
|
||||||
# ActiveRecord::Base.include_root_in_json = false
|
# ActiveRecord::Base.include_root_in_json = false
|
||||||
});
|
```
|
||||||
|
|
||||||
project = Project.find(1)
|
```bash
|
||||||
project = Project.findByTitle("hello")
|
project = Project.find(1)
|
||||||
|
project = Project.findByTitle("hello")
|
||||||
|
|
||||||
project.markAsDone()
|
project.markAsDone()
|
||||||
|
```
|
||||||
|
|
||||||
### Persistence
|
### Persistence
|
||||||
|
|
||||||
Project "hi", ->
|
```bash
|
||||||
|
Project "hi", ->
|
||||||
@persistence Model.REST, "/projects"
|
@persistence Model.REST, "/projects"
|
||||||
@persistence Model.localStorage
|
@persistence Model.localStorage
|
||||||
|
```
|
||||||
|
|
||||||
Project.load ->
|
```bash
|
||||||
// loaded
|
Project.load ->
|
||||||
|
# loaded
|
||||||
|
```
|
||||||
|
|
||||||
### Attrs
|
### Attrs
|
||||||
|
|
||||||
project = new Project(name: "Hello")
|
```bash
|
||||||
|
project = new Project(name: "Hello")
|
||||||
|
|
||||||
project.attr('name', "Hey")
|
project.attr('name', "Hey")
|
||||||
project.attr('name')
|
project.attr('name')
|
||||||
|
|
||||||
project.save()
|
project.save()
|
||||||
project.destroy()
|
project.destroy()
|
||||||
|
```
|
||||||
|
|
||||||
### Collection
|
### Collection
|
||||||
|
|
||||||
Food.add(egg)
|
```bash
|
||||||
Food.all()
|
Food.add(egg)
|
||||||
Food.select (food) -> ...
|
Food.all()
|
||||||
Food.first()
|
Food.select (food) -> ...
|
||||||
|
Food.first()
|
||||||
|
```
|
||||||
|
|
||||||
Food.find(id)
|
```bash
|
||||||
|
Food.find(id)
|
||||||
|
```
|
||||||
|
|
||||||
### Events
|
### Events
|
||||||
|
|
||||||
Project.bind "add", (obj) ->
|
```bash
|
||||||
Project.bind "remove", (obj) ->
|
# Classes
|
||||||
|
Project.bind "add", (obj) ->
|
||||||
|
Project.bind "remove", (obj) ->
|
||||||
|
```
|
||||||
|
|
||||||
# Instances
|
```bash
|
||||||
project.bind "update", ->
|
# Instances
|
||||||
project.bind "destroy", ->
|
project.bind "update", ->
|
||||||
|
project.bind "destroy", ->
|
||||||
|
```
|
||||||
|
|
||||||
project.trigger "turn_blue"
|
```bash
|
||||||
|
project.trigger "turn_blue"
|
||||||
|
```
|
||||||
|
|
||||||
http://benpickles.github.io/js-model/
|
## References
|
||||||
|
{: .-one-column}
|
||||||
|
|
||||||
|
- <http://benpickles.github.io/js-model/>
|
||||||
|
|
Loading…
Reference in New Issue