Skip to content

Instantly share code, notes, and snippets.

@mrrooijen
Created July 31, 2012 18:17
Show Gist options
  • Save mrrooijen/3219143 to your computer and use it in GitHub Desktop.
Save mrrooijen/3219143 to your computer and use it in GitHub Desktop.
Useful Batman.js Filters.
Batman.mixin Batman.Filters,
isCreating: (model) -> model?.get("lifecycle.state") == "creating"
isSaving: (model) -> model?.get("lifecycle.state") == "saving"
isDestroying: (model) -> model?.get("lifecycle.state") == "destroying"
isPersisting: (model) -> model?.get("lifecycle.state") in ["saving", "creating"]
isUndefined: (input) -> input == undefined
isNull: (input) -> input == null
isBlank: (input) -> input in [undefined, null, ""]
eq: (input, value) -> input == value
ne: (input, value) -> input != value
gt: (input, value) -> input > value
lt: (input, value) -> input < value
gte: (input, value) -> input >= value
lte: (input, value) -> input <= value
length: (input) -> input?.length
indexOf: (set, iteration) -> set?.indexOf(iteration)
isFirst: (set, iteration) -> set?.indexOf(iteration) == 0
isLast: (set, iteration) -> set?.length - set.indexOf(iteration) == 1
isEven: (input) -> input % 2 == 0
isOdd: (input) -> input % 2 != 0
@seivan
Copy link

seivan commented Aug 1, 2012

Dude I made a website batmanfilters - where people can put their filters in ^^

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment