Skip to content

How to reset recursive time driver #272

Open
@mrEvgenX

Description

@mrEvgenX

I need to increase counter by timer, then go to another view goSeeingCounted to see result for further processing.
Seems recursed timer is unstoppable. Any help?

Example of code to be fixed (playground):

const { div, p, button } = Moon.view.m;

const goSeeingCounted = ({ data }) => {
  return {
	  data,
	  time: undefined,
	  view: <viewSeeCounted counter=data.counter/>
	};
};

const viewCounter = ({ counter }) => (
	<div>
		<p>{counter}</p>
		<button @click=goSeeingCounted>Create</button>
	</div>
);

const viewSeeCounted = ({ counter }) => (
	<div>
		<p>Result: {counter}</p>
	</div>
);

const tick = ({data}) => {
  let newData = {
	counter: 0
  }
  if (data !== undefined) {
	newData.counter = data.counter + 1;
  }  
  return {
	data: newData,
	time: { 1000: tick },
    view: <viewCounter counter=newData.counter/>
  };
}

Moon.use({
	data: Moon.data.driver,
  	time: Moon.time.driver,
	view: Moon.view.driver("#root")
});

Moon.run(tick);

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions