Skip to content

Instantly share code, notes, and snippets.

@DesignByOnyx
Last active May 25, 2018 19:30
Show Gist options
  • Select an option

  • Save DesignByOnyx/83fb62f641ddaf649e08d5d8b58e7d05 to your computer and use it in GitHub Desktop.

Select an option

Save DesignByOnyx/83fb62f641ddaf649e08d5d8b58e7d05 to your computer and use it in GitHub Desktop.

Revisions

  1. DesignByOnyx revised this gist May 25, 2018. 1 changed file with 9 additions and 2 deletions.
    11 changes: 9 additions & 2 deletions ylem-model.md
    Original file line number Diff line number Diff line change
    @@ -38,17 +38,24 @@
    const { people } = this.props;
    <ul>
    {people.map(person => (
    <li><Individual person={person} /></li>
    <li key={person.id}><Individual person={person} /></li>
    ))}
    </ul>
    }
    };

    export Default PersonList;
    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 }} />
    ```
  2. DesignByOnyx revised this gist May 25, 2018. 1 changed file with 1 addition and 0 deletions.
    1 change: 1 addition & 0 deletions ylem-model.md
    Original 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' },
  3. DesignByOnyx revised this gist May 25, 2018. 1 changed file with 10 additions and 4 deletions.
    14 changes: 10 additions & 4 deletions ylem-model.md
    Original file line number Diff line number Diff line change
    @@ -14,15 +14,21 @@
    });
    ```

    2. Use the DataProvider component to provide data to your components:
    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 Person = dataProvider(Person, 'person', ({ person }) => {
    return <li>{person.name} is {person.age} years old.</li>;
    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 => (
    <Person person={person} />
    <li><Individual person={person} /></li>
    ))}
    </ul>
    }
  4. DesignByOnyx revised this gist May 25, 2018. 1 changed file with 5 additions and 1 deletion.
    6 changes: 5 additions & 1 deletion ylem-model.md
    Original 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 => (
    <li>{person.name} is {person.age} years old.</li>
    <Person person={person} />
    ))}
    </ul>
    }
  5. DesignByOnyx revised this gist May 25, 2018. 1 changed file with 3 additions and 3 deletions.
    6 changes: 3 additions & 3 deletions ylem-model.md
    Original 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 } }} />
    ```
    ```js
    <PersonList query={{ age: { $gt: 27 } }} />
    ```
  6. DesignByOnyx revised this gist May 25, 2018. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion ylem-model.md
    Original file line number Diff line number Diff line change
    @@ -36,7 +36,7 @@
    export Default PersonList;
    ```

    And use the component like this:
    3. Use the component like this, pass a query for filtering

    ```js
    <PersonList query={{ age: { $gt: 27 } }} />
  7. DesignByOnyx renamed this gist May 25, 2018. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion ylem-model → ylem-model.md
    Original 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:

  8. DesignByOnyx created this gist May 25, 2018.
    43 changes: 43 additions & 0 deletions ylem-model
    Original 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 } }} />
    ```