Skip to content

RFE: MX support to simplify Dart Stream processing #1

Open
@kennytilton

Description

@kennytilton

Background

Currently, a widget can fairly elegantly handle a stream with a pair of cells:

{:msg-source (cF+ [:watch (fn [_ me ^#/(async/StreamController String) new-source old-source _]
                            (.listen (.-stream ^#/(async/StreamController String) new-source)
                              (fn [^String msg]
                                (mset! me :msg-rcvd msg))))]
               (mget (fm* :msg-sender) :msg-stream))
 :msg-rcvd   (cI "<none>" :ephemeral? true)}

Nice, but Streams are common in Flutter.

The RFE: support streams with one cell

Because Streams are fairly common in Dart/Flutter, we would like to handle a stream with a single cell, perhaps:

{:msg-rcvd (cF+ [:sink (fn [_ me ^#/(async/StreamController String) new-source old-source _]
                         (.listen (.-stream ^#/(async/StreamController String) new-source)
                           (fn [^String msg]
                             (mset! me :msg-rcvd msg))))]
             (mget (fm* :msg-sender) :msg-stream))}

Notes:

  • if the formula has a dependency, meaning it could end up seeing a new stream, we should seamlessly change over to that;
  • the :async? option starts at nil pending the result. Do we need to make that a specifiable value?
  • should this cell default to :ephemeral true?

Also, a stream can have a lot of callbacks:

  onPause: () => print('Paused'),
  onResume: () => print('Resumed'),
  onCancel: () => print('Cancelled'),
  onListen: () => print('Listens'),

Do we have to address those? One solution might be to handle elaborate stream processing with the current 2-cell approach, and reserve the 1-cell approach for simple cases. The 2-cell approach is not all that bad.

Comments? Questions?

Metadata

Metadata

Assignees

Labels

No labels
No labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions