dedotdev / dedot

Delightful JavaScript client for Polkadot & Substrate
https://dedot.dev
Apache License 2.0
31 stars 4 forks source link

breaking: add `find` & `filter` methods to system & contract events #211

Closed sinzii closed 1 month ago

sinzii commented 1 month ago

We're adding find & filter methods to api.events & contracts.events so it will be easier to find or filter a particular event.

System Event:

// before
const remarkEvent = events.map(({ event }) => event).find(api.events.system.Remarked.is);

// after
const remarkEvent = api.events.system.Remarked.find(events);

Contract Event:

// before
const contractEventRecords = events.filter((r) => api.events.contracts.ContractEmitted.is(r.event));

const flippedEvent = contractEventRecords
  .map((e) => contract.decodeEvent(e))
  .find(contract.events.Flipped.is);

// after
const flippedEvent = contract.events.Flipped.find(events);

Breaking changing as we're removing the as method in favor of the new ones.