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

frint-model: Introduce .get$() for streaming values #158

Closed
fahad19 opened this issue Apr 3, 2017 · 1 comment
Closed

frint-model: Introduce .get$() for streaming values #158

fahad19 opened this issue Apr 3, 2017 · 1 comment
Assignees
Labels

Comments

@fahad19
Copy link
Member

fahad19 commented Apr 3, 2017

Currently

Right now we can do:

const Todo = createModel({...});

const todo = new Todo({ title: 'My First Todo' });
const title = todo.get('title'); // `My First Todo`

Expected feature

It would be beneficial for form management, if we can observe Model values too:

const title$ = todo.get$('title');

title$.subscribe(x => console.log(x));

todo.set('title', 'Updated title'); // prints out title in console

Benefit

Then for handling forms in component, we could do something like this with frint-react's observe:

import React from 'react';
import { observe, streamProps } from 'frint-react';

const FormComponent = React.createClass({...});

export default observe(function () {
  const todo = new Todo({ title: 'My todo' });

  return streamProps()
    .set(
      todo.get$(),
      todoAttributes => ({ todo: todoAttributes })
    )
    .get$();
})(FormComponent);
@fahad19 fahad19 added the feature label Apr 3, 2017
@fahad19
Copy link
Member Author

fahad19 commented Apr 22, 2017

Done in #166

@fahad19 fahad19 closed this as completed Apr 22, 2017
@fahad19 fahad19 self-assigned this Apr 22, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant