Last active
May 25, 2018 19:30
-
-
Save DesignByOnyx/83fb62f641ddaf649e08d5d8b58e7d05 to your computer and use it in GitHub Desktop.
Revisions
-
DesignByOnyx revised this gist
May 25, 2018 . 1 changed file with 9 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -38,17 +38,24 @@ const { people } = this.props; <ul> {people.map(person => ( <li key={person.id}><Individual person={person} /></li> ))} </ul> } }; export { Individual, PersonList }; ``` 3. Use the component like this, pass a query for filtering ```js // Load a single person <Individual query={{ id: 1234 }} /> // Load a list of people <PersonList query={{ age: { $gt: 27 } }} /> // Pass data directly to bypass loading data: <Individual person={{ name: 'Justin', age: 35 }} /> ``` -
DesignByOnyx revised this gist
May 25, 2018 . 1 changed file with 1 addition and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -4,6 +4,7 @@ import { Model, transport } from 'ylem-model'; const Person = Model({ id: { type: 'number', identity: true }, name: { type: 'string' }, email: { type: 'string' }, age: { type: 'number' }, -
DesignByOnyx revised this gist
May 25, 2018 . 1 changed file with 10 additions and 4 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -14,15 +14,21 @@ }); ``` 2. Use the dataProvider to provide data to your components. ```js dataProvider(Model, property, Component); ``` The dataProvider generates a HoC which will load data (using an optional query) and provide the results to the underlying component. The results will be exposed on the "property" specifed (the second param to the `dataProvider` function). The intermediate states are handled for you (loading, error, no data). The underlying component is only rendered when the data loads successfully. ```js import React from 'react'; import { dataProvider } from 'ylem-model'; import Person from './person'; const Individual = dataProvider(Person, 'person', ({ person }) => { return <div>{person.name} is {person.age} years old.</div>; }); @dataProvider(Person, 'people') @@ -31,7 +37,7 @@ const { people } = this.props; <ul> {people.map(person => ( <li><Individual person={person} /></li> ))} </ul> } -
DesignByOnyx revised this gist
May 25, 2018 . 1 changed file with 5 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -20,14 +20,18 @@ import React from 'react'; import { dataProvider } from 'ylem-model'; import Person from './person'; const Person = dataProvider(Person, 'person', ({ person }) => { return <li>{person.name} is {person.age} years old.</li>; }); @dataProvider(Person, 'people') class PersonList extends React.Component { render() { const { people } = this.props; <ul> {people.map(person => ( <Person person={person} /> ))} </ul> } -
DesignByOnyx revised this gist
May 25, 2018 . 1 changed file with 3 additions and 3 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -38,6 +38,6 @@ 3. Use the component like this, pass a query for filtering ```js <PersonList query={{ age: { $gt: 27 } }} /> ``` -
DesignByOnyx revised this gist
May 25, 2018 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -36,7 +36,7 @@ export Default PersonList; ``` 3. Use the component like this, pass a query for filtering ```js <PersonList query={{ age: { $gt: 27 } }} /> -
DesignByOnyx renamed this gist
May 25, 2018 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -12,7 +12,7 @@ export default transport(Person, { url: '/api/person' }); ``` 2. Use the DataProvider component to provide data to your components: -
DesignByOnyx created this gist
May 25, 2018 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,43 @@ 1. Define your models with a transport (this is just sugar for can-connect) ```js import { Model, transport } from 'ylem-model'; const Person = Model({ name: { type: 'string' }, email: { type: 'string' }, age: { type: 'number' }, }); export default transport(Person, { url: '/api/person' }); ``` 2. Use the DataProvider component to provide data to your components: ```js import React from 'react'; import { dataProvider } from 'ylem-model'; import Person from './person'; @dataProvider(Person, 'people') class PersonList extends React.Component { render() { const { people } = this.props; <ul> {people.map(person => ( <li>{person.name} is {person.age} years old.</li> ))} </ul> } }; export Default PersonList; ``` And use the component like this: ```js <PersonList query={{ age: { $gt: 27 } }} /> ```