Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make models streamable #166

Merged
merged 4 commits into from Apr 22, 2017
Merged

Make models streamable #166

merged 4 commits into from Apr 22, 2017

Conversation

fahad19
Copy link
Member

@fahad19 fahad19 commented Apr 20, 2017

What's done

Models now support Observables, for streaming changes as they happen. This would be of very high impact for dealing with forms in observed React components.

Usage

Import:

import { createModel } from 'frint-model';

Create Model class:

const Shirt = createModel({});

Building a new model instance:

const shirt = new Shirt({
  color: 'blue',
  size: 'medium',
});

The model instance can also be observed for changes:

shirt.get$().subscribe(function (shirtAttributes) {
  // triggered when the model had any change
});

shirt.get$('color').subscribe(function (color) {
  // triggered when the model's `color` key changes
});

@coveralls
Copy link

Coverage Status

Coverage decreased (-0.05%) to 97.26% when pulling 5c13282 on frint-model-reactive into f262963 on master.

}

Model.prototype.get = function get(key) {
function getFromAttributes(attributes, key) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just curious, why you are not adding any description (eg jsdoc)?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

till now, we have always maintained the API documentation in package's own README whenever we made changes in code. but I agree jsdoc would be a better approach.

would really welcome PRs to speed that process up :)

const person = new Person({ name: 'Helga Hufflepuff' });
person.get$().subscribe(function (personAttributes) {
expect(personAttributes).to.deep.equal({
name: 'Helga Hufflepuff',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

❤️

@coveralls
Copy link

Coverage Status

Coverage increased (+0.05%) to 97.363% when pulling 7ae752e on frint-model-reactive into f262963 on master.

@fahad19 fahad19 merged commit abf9aee into master Apr 22, 2017
@fahad19 fahad19 deleted the frint-model-reactive branch April 22, 2017 17:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants