actions.tsx 1.2 KB

1234567891011121314151617181920212223242526272829303132333435
  1. /**
  2. * Copyright (c) 2018 - 2019 mol* contributors, licensed under MIT, See LICENSE file for more info.
  3. *
  4. * @author David Sehnal <david.sehnal@gmail.com>
  5. */
  6. import * as React from 'react';
  7. import { PluginUIComponent } from '../base';
  8. import { ApplyActionContol } from './apply-action';
  9. import { State } from 'mol-state';
  10. export class StateObjectActions extends PluginUIComponent<{ state: State, nodeRef: string }> {
  11. get current() {
  12. return this.plugin.state.behavior.currentObject.value;
  13. }
  14. componentDidMount() {
  15. this.subscribe(this.plugin.state.behavior.currentObject, o => {
  16. this.forceUpdate();
  17. });
  18. this.subscribe(this.plugin.events.state.object.updated, ({ ref, state }) => {
  19. const current = this.current;
  20. if (current.ref !== ref || current.state !== state) return;
  21. this.forceUpdate();
  22. });
  23. }
  24. render() {
  25. const { state, nodeRef: ref } = this.props;
  26. const cell = state.cells.get(ref)!;
  27. const actions = state.actions.fromCell(cell, this.plugin);
  28. return actions.map((act, i) => <ApplyActionContol plugin={this.plugin} key={`${act.id}`} state={state} action={act} nodeRef={ref} />);
  29. }
  30. }