effects.ts 593 B

12345678910111213141516171819
  1. import { StateEffectType, Transaction } from '@codemirror/state'
  2. import { ViewUpdate } from '@codemirror/view'
  3. export const hasEffect =
  4. <T>(effectType: StateEffectType<T>) =>
  5. (tr: Transaction) =>
  6. tr.effects.some(effect => effect.is(effectType))
  7. export const updateHasEffect =
  8. <T>(effectType: StateEffectType<T>) =>
  9. (update: ViewUpdate) =>
  10. update.transactions.some(tr =>
  11. tr.effects.some(effect => effect.is(effectType))
  12. )
  13. export const findEffect =
  14. <T>(effectType: StateEffectType<T>) =>
  15. (tr: Transaction) =>
  16. tr.effects.find(effect => effect.is(effectType))