Skip to content

Commit

Permalink
Account for documented expressions in bind recurrence relations.
Browse files Browse the repository at this point in the history
  • Loading branch information
amyjko committed Mar 2, 2024
1 parent 44e575c commit c731427
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ Dates are in `YYYY-MM-DD` format and versions are in [semantic versioning](http:
- Fixed list spread doc example.
- Better unused bind conflict message.
- Narrowed parsing of structure refinements to avoid conflicting with spreads in lists.
- Account for documented expressions in bind recurrence relations.

## 0.9.34 2024-02-24

Expand Down
15 changes: 9 additions & 6 deletions src/nodes/Bind.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ import ExpressionPlaceholder from './ExpressionPlaceholder';
import Refer from '../edit/Refer';
import UnknownType from './UnknownType';
import type Locales from '../locale/Locales';
import DocumentedExpression from './DocumentedExpression';

export default class Bind extends Expression {
readonly docs?: Docs;
Expand Down Expand Up @@ -603,18 +604,20 @@ export default class Bind extends Expression {
]
: [
new Start(this, (evaluator) => {
const value =
this.value instanceof DocumentedExpression
? this.value.expression
: this.value;

// Before evaluating the bind's value, see if the value expression previously evaluated to
// a stream, and if so, bind this Bind's names to the previous value. This allows
// for stream-based recurrence relations, where a stream or reaction's future values can be
// affected by their past values.
if (
this.value instanceof Evaluate ||
this.value instanceof Reaction
value instanceof Evaluate ||
value instanceof Reaction
) {
const stream = evaluator.getStreamFor(
this.value,
true,
);
const stream = evaluator.getStreamFor(value, true);
const latest = stream?.latest();
if (latest) evaluator.bind(this.names, latest);
}
Expand Down

0 comments on commit c731427

Please sign in to comment.