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

[CURVE and RUNE]: drawing should not depend on evaluation result #65

Closed
martin-henz opened this issue Jun 4, 2021 · 2 comments · Fixed by #126
Closed

[CURVE and RUNE]: drawing should not depend on evaluation result #65

martin-henz opened this issue Jun 4, 2021 · 2 comments · Fixed by #126
Assignees
Labels
Enhancement [Category] New feature request

Comments

@martin-henz
Copy link
Member

martin-henz commented Jun 4, 2021

Feature

import {draw_connected_full_view, unit_circle } from "curve";
draw_connected_full_view(500)(unit_circle);
0;

should draw the circle. Currently the drawers only draw when the result of the evaluation is a drawing. With the separate curve window, we can eliminate this hack.

@martin-henz martin-henz added the Enhancement [Category] New feature request label Jun 4, 2021
@Anonymxtrix
Copy link
Contributor

Anonymxtrix commented Jul 25, 2021

This issue is related to #56.

Proposed Solution

Outcome

The solution aims to achieve the following outcomes.

  • To allow module bundles and tabs to have access to a shared state without needing to rely on the evaluation result of the Source Program.

In the Source evaluation context

export interface Context<T = any> {
  // Here lies all information related to the importing of modules
  modules: {
    // Individually, each bundle and tab will have access to the corresponding state.
    // Bundles and tabs will be able to directly read and mutate this shared state to
    // interact with each other. 
    state: {
      module_name: {
        // counter: 0
      }
    }
    tabs: any[]
  }
}

During the compilation process of the bundles, the bundle should be wrapped in a manner similar to NodeJS modules. 3 main things will be passed into the wrapped bundle function as arguments, exports, state and config. exports should contain the functions to be provided by the module to Source programmers to use in Source programs. state should be a reference to the shared state in the evaluation Context in JS-Slang. config will be the new name for __params used previously.

function (exports, state, config) {
  // Here lies the program written in the module bundles. 
  
  // To expose a counter to the module's tab
  state.counter = config.counter.defaultValue
  
  exports.increment = func () {
    state.counter++
  }

  exports.decrement= func () {
    state.counter--
  }
}

The module tab should be able to access this counter through the DebuggerContext which should contain a reference to the state through modules.state in the returned Context

Example

The curves module currently has the problem of not being able to render drawings without depending on the evaluation result. This solution will solve this problem in the following manner.

The curves bundle will implement a function draw which appends the curve to the array of curves to be drawn.

function draw(curve: Curve) {
  state.drawnCurves = state.drawnCurves.append(curve)
}

The curves tab will access the state and map out the drawnCurves as follows.

class Curves extends React.Component<...> {
  render() {
    return (
      <div>
        // ... use this.props.state.drawnCurves.map(...)
      </div>
    )
  }
} 

@martin-henz
Copy link
Member Author

Yes, this makes sense to me.

@solarrabbit99 solarrabbit99 self-assigned this Jul 26, 2021
@martin-henz martin-henz changed the title [CURVE]: drawing should not depend on evaluation result [CURVE and RUNE]: drawing should not depend on evaluation result Jul 30, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Enhancement [Category] New feature request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants