1
0

linkFoundation.ts 986 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. import BaseFoundation, { DefaultAdapter } from '../base/foundation';
  2. import { AnchorAdapter } from './foundation';
  3. export interface LinkAdapter extends DefaultAdapter {
  4. addLink: AnchorAdapter['addLink'];
  5. removeLink: AnchorAdapter['removeLink'];
  6. }
  7. export default class LinkFoundation extends BaseFoundation<LinkAdapter> {
  8. constructor(adapter: LinkAdapter) {
  9. super({ ...adapter });
  10. }
  11. init() {
  12. // this.setInitValue();
  13. }
  14. // eslint-disable-next-line @typescript-eslint/no-empty-function
  15. destroy() {}
  16. handleAddLink() {
  17. const href = this._adapter.getProp('href');
  18. this._adapter.addLink(href);
  19. }
  20. handleUpdateLink(href: string, prevHref: string) {
  21. if (href !== prevHref) {
  22. this._adapter.removeLink(prevHref);
  23. this._adapter.addLink(href);
  24. }
  25. }
  26. handleRemoveLink() {
  27. const href = this._adapter.getProp('href');
  28. this._adapter.removeLink(href);
  29. }
  30. }