alt icon indicating copy to clipboard operation
alt copied to clipboard

alt.generateActions should also accept objects or arrays

Open goatslacker opened this issue 10 years ago • 5 comments
trafficstars

alt.generateActions('foo', 'bar', { baz() { } })

or

alt.generateActions('foo', 'bar', ['baz', () => {}])

goatslacker avatar Jul 15 '15 20:07 goatslacker

the first one seems to have more sense.

i always get stuck for having many syntactic choices. not sure if it's a good idea; but I find it shorter than this (because classes are verbose):

class FooActions {
  constructor() {
    this.generateActions('foo', 'bar');
  }

  baz() {
  }
}

srph avatar Jul 16 '15 01:07 srph

The first makes more sense to me as well, but will we have issues with the action name on minification?

jdlehman avatar Jul 16 '15 01:07 jdlehman

Right you'd have to tell the minifier to not minify it, plus there's the risk of conflicting keys.

goatslacker avatar Jul 16 '15 02:07 goatslacker

Is there any implementation on this? That would be very useful, I have to create the verbose 'class' syntax just for one action (all others go through generateActions).

afilp avatar Sep 06 '15 22:09 afilp

what I do:

const dispatch = x => x

const FooActions = alt.createActions({
  foo: dispatch,
  bar: dispatch,
  baz: dispatch,
})

You can further reduce this if you want to something else that's easily implementable in userland.

goatslacker avatar Sep 07 '15 01:09 goatslacker