Skip to content

Commit

Permalink
initial state should be clones now state is a class
Browse files Browse the repository at this point in the history
  • Loading branch information
RomainFranceschini committed Apr 27, 2020
1 parent 306fe52 commit 4ad8cc5
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 12 deletions.
4 changes: 2 additions & 2 deletions src/quartz/atomic.cr
Original file line number Diff line number Diff line change
Expand Up @@ -83,10 +83,10 @@ module Quartz
@elapsed = @elapsed.rescale(@@precision_level)
end

def initialize(name, state, initial_state = nil)
def initialize(name, state)
super(name)
@elapsed = @elapsed.rescale(@@precision_level)
self.initial_state = initial_state if initial_state
self.initial_state = state.clone
self.state = state
end

Expand Down
4 changes: 2 additions & 2 deletions src/quartz/dtss/atomic.cr
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ module Quartz::DTSS
super(name)
end

def initialize(name, state, initial_state = nil)
def initialize(name, state)
super(name)
self.initial_state = initial_state if initial_state
self.initial_state = state.clone
self.state = state
end

Expand Down
13 changes: 8 additions & 5 deletions src/quartz/json.cr
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,11 @@ module Quartz

{{@type}}.new(
name.as(String),
state.as({{ (@type.constant(:State)).id }}),
initial_state.as({{ (@type.constant(:State)).id }})
).tap { |model| model.elapsed = elapsed.as(Duration) }
state.as({{ (@type.constant(:State)).id }})
).tap { |model|
model.elapsed = elapsed.as(Duration)
model.initial_state = initial_state.as({{ (@type.constant(:State)).id }})
}
end

def to_json(json : ::JSON::Builder)
Expand Down Expand Up @@ -115,8 +117,9 @@ module Quartz
{{@type}}.new(
name.as(String),
state.as({{ (@type.constant(:State)).id }}),
initial_state.as({{ (@type.constant(:State)).id }})
)
).tap { |m|
m.initial_state = initial_state.as({{ (@type.constant(:State)).id }})
}
end

def to_json(json : ::JSON::Builder)
Expand Down
2 changes: 1 addition & 1 deletion src/quartz/multi_component/component.cr
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ module Quartz
def initialize(name, state)
super(name)
@elapsed = @elapsed.rescale(@@precision_level)
self.initial_state = state
self.initial_state = state.clone
self.state = state
end

Expand Down
3 changes: 1 addition & 2 deletions src/quartz/state.cr
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,6 @@ module Quartz
{% end %}
end

def_clone

def ==(other : self)
{% for ivar in @type.instance_vars %}
return false unless @{{ivar.id}} == other.{{ivar.id}}
Expand Down Expand Up @@ -200,6 +198,7 @@ module Quartz
STATE_VARS = [] of Nil
STATE_PARAMS = [] of Nil
{{ yield }}
def_clone
end

def_properties
Expand Down

0 comments on commit 4ad8cc5

Please sign in to comment.