mirror of
https://github.com/atom/atom.git
synced 2026-01-24 06:18:03 -05:00
35 lines
644 B
CoffeeScript
35 lines
644 B
CoffeeScript
Grim = require 'grim'
|
|
if Grim.includeDeprecatedAPIs
|
|
module.exports = require('theorist').Model
|
|
return
|
|
|
|
PropertyAccessors = require 'property-accessors'
|
|
|
|
nextInstanceId = 1
|
|
|
|
module.exports =
|
|
class Model
|
|
PropertyAccessors.includeInto(this)
|
|
|
|
@resetNextInstanceId: -> nextInstanceId = 1
|
|
|
|
alive: true
|
|
|
|
constructor: (params) ->
|
|
@assignId(params?.id)
|
|
|
|
assignId: (id) ->
|
|
@id ?= id ? nextInstanceId++
|
|
|
|
@::advisedAccessor 'id',
|
|
set: (id) -> nextInstanceId = id + 1 if id >= nextInstanceId
|
|
|
|
destroy: ->
|
|
return unless @isAlive()
|
|
@alive = false
|
|
@destroyed?()
|
|
|
|
isAlive: -> @alive
|
|
|
|
isDestroyed: -> not @isAlive()
|