     val.join " "
 
   unpack: (val) ->
-    if val? and val isnt "" then val.split(/\s+/) else []
+    if val? and val isnt ""
+      val.split(/\s+/)
+    else []
 
   get: ->
     @unpack(localStorage.getItem(@key()))

PREFIX = "amck"


class Repo
  constructor: (@name) ->

  key: ->
    PREFIX + @name

    localStorage.setItem(@key(), @pack(val))

  get_notify: (event) ->
    event in @get()

  set_notify: (event, value) ->
    s = (e for e in @get() when e isnt event)
    s.push(event) if value
    @set(s)

    if (s.length > 0) then @watch() else @unwatch()

  csrf_token: ->
    $('meta[name="csrf-token"]').attr("content")

  toggle_watch: ->
    $.ajax({
      type: "POST",
      url: @name + "/toggle_watch",
      headers: { "X-CSRF-Token": @csrf_token() }
    })

  watch: ->
    unless @is_watched
      @toggle_watch()
      @is_watched = true

  unwatch: ->
    if @is_watched
      @toggle_watch()
      @is_watched = false



class Notifications
