Skip to content

Commit

Permalink
fixed api of adding and removing elements
Browse files Browse the repository at this point in the history
  • Loading branch information
JanBliznicenko committed Jan 21, 2020
1 parent ae8c7f9 commit cd93c02
Showing 1 changed file with 16 additions and 9 deletions.
25 changes: 16 additions & 9 deletions repository/OpenPonk-Model/OPModelObject.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ Class {
'uuid',
'name'
],
#category : 'OpenPonk-Model-ModelObjects'
#category : #'OpenPonk-Model-ModelObjects'
}

{ #category : #'instance creation' }
Expand All @@ -23,22 +23,25 @@ OPModelObject class >> named: aString [
{ #category : #adding }
OPModelObject >> add: anElement [
(elements includes: anElement)
ifTrue: [ ^ self ].
ifTrue: [ ^ anElement ].
anElement addedTo: self.
elements add: anElement.
anElement when: OPElementChanged do: [ self changed ].
self announceAdded: anElement
self announceAdded: anElement.
^ anElement
]

{ #category : #adding }
OPModelObject >> addAll: aCollection [
aCollection do: [ :each | self add: each ]
aCollection do: [ :each | self add: each ].
^ aCollection
]

{ #category : #adding }
OPModelObject >> addedTo: anObject [
owner := anObject.
self changed
self changed.
^ anObject
]

{ #category : #accessing }
Expand Down Expand Up @@ -120,22 +123,26 @@ OPModelObject >> relatedElements [

{ #category : #removing }
OPModelObject >> remove [
self owner remove: self
^ self owner remove: self
]

{ #category : #removing }
OPModelObject >> remove: anElement [
(elements includes: anElement)
ifFalse: [ ^ self ].
ifFalse: [ ^ anElement ].
anElement announcer unsubscribe: self.
anElement removeFrom: self.
elements remove: anElement.
self announceRemoved: anElement
self announceRemoved: anElement.
^ anElement
]

{ #category : #removing }
OPModelObject >> removeAll [
[ elements isNotEmpty ] whileTrue: [ self remove: elements anyOne ]
| removed |
removed := elements copy.
[ elements isNotEmpty ] whileTrue: [ self remove: elements anyOne ].
^ removed
]

{ #category : #removing }
Expand Down

0 comments on commit cd93c02

Please sign in to comment.