Skip to content

Commit a80d9c2

Browse files
ngokevindmarcos
authored andcommitted
remove state mixins (#3171)
1 parent 3231356 commit a80d9c2

File tree

4 files changed

+15
-67
lines changed

4 files changed

+15
-67
lines changed

examples/showcase/tracked-controls/components/aabb-collider.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ AFRAME.registerComponent('aabb-collider', {
6363
return collisions.indexOf(el) === -1;
6464
}).forEach(function removeState (el) {
6565
el.removeState(self.data.state);
66+
el.emit('hitend');
6667
});
6768
// Store new collisions
6869
this.collisions = collisions;

examples/showcase/tracked-controls/components/grab.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ AFRAME.registerComponent('grab', {
4646
this.grabbing = false;
4747
if (!hitEl) { return; }
4848
hitEl.removeState(this.GRABBED_STATE);
49+
hitEl.emit('grabend');
4950
this.hitEl = undefined;
5051
},
5152

examples/showcase/tracked-controls/index.html

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,18 +9,24 @@
99
<script src="components/grab.js"></script>
1010
<script src="components/ground.js"></script>
1111
<script src="shaders/skyGradient.js"></script>
12+
<script src="https://unpkg.com/[email protected]/dist/aframe-event-set-component.min.js"></script>
1213
</head>
1314
<body>
14-
<a-scene fog="color: #bc483e; near: 0; far: 65;">
15+
<a-scene cursor="rayOrigin: mouse" fog="color: #bc483e; near: 0; far: 65;">
1516
<a-assets>
1617
<a-mixin id="cube"
18+
event-set__grab="material.color: #FFEF4F"
19+
event-set__grabend="material.color: #F2E646"
20+
event-set__hit="material.color: #F2E646"
21+
event-set__hitend="material.color: #EF2D5E"
22+
event-set__mousedown="material.color: #FFEF4F"
23+
event-set__mouseenter="material.color: #F2E646"
24+
event-set__mouseleave="material.color: #EF2D5E"
25+
event-set__mouseup="material.color: #F2E646"
1726
geometry="primitive: box; height: 0.30; width: 0.30; depth: 0.30"
1827
material="color: #EF2D5E;"></a-mixin>
19-
<a-mixin id="cube-collided"
20-
material="color: #F2E646;"></a-mixin>
21-
<a-mixin id="cube-grabbed"
22-
material="color: #F2E646;"></a-mixin>
2328
</a-assets>
29+
2430
<!-- Hands -->
2531
<a-entity hand-controls="left" aabb-collider="objects: .cube;" grab></a-entity>
2632
<a-entity hand-controls="right" aabb-collider="objects: .cube;" grab></a-entity>

src/core/a-entity.js

Lines changed: 2 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ var THREE = require('../lib/three');
55
var utils = require('../utils/');
66

77
var AEntity;
8-
var bind = utils.bind;
98
var debug = utils.debug('core:a-entity:debug');
109
var warn = utils.debug('core:a-entity:warn');
1110

@@ -131,62 +130,6 @@ var proto = Object.create(ANode.prototype, {
131130
}
132131
},
133132

134-
/**
135-
* Add new mixin for each mixin with state suffix.
136-
*/
137-
mapStateMixins: {
138-
value: function (state, op) {
139-
var mixins;
140-
var mixinIds;
141-
var i;
142-
143-
mixins = this.getAttribute('mixin');
144-
145-
if (!mixins) { return; }
146-
mixinIds = mixins.split(' ');
147-
for (i = 0; i < mixinIds.length; i++) {
148-
op(mixinIds[i] + '-' + state);
149-
}
150-
this.updateComponents();
151-
}
152-
},
153-
154-
/**
155-
* Handle update of mixin states (e.g., `box-hovered` where `box` is the mixin ID and
156-
* `hovered` is the entity state.
157-
*/
158-
updateStateMixins: {
159-
value: function (newMixins, oldMixins) {
160-
var diff;
161-
var newMixinIds;
162-
var oldMixinIds;
163-
var i;
164-
var j;
165-
var stateMixinEls;
166-
167-
newMixinIds = newMixins.split(' ');
168-
oldMixinIds = (oldMixins || '') ? oldMixins.split(' ') : [];
169-
170-
// List of mixins that might have been removed on update.
171-
diff = oldMixinIds.filter(function (i) { return newMixinIds.indexOf(i) < 0; });
172-
173-
// Remove removed mixins.
174-
for (i = 0; i < diff.length; i++) {
175-
stateMixinEls = document.querySelectorAll('[id^=' + diff[i] + '-]');
176-
for (j = 0; j < stateMixinEls.length; j++) {
177-
this.unregisterMixin(stateMixinEls[j].id);
178-
}
179-
}
180-
181-
// Add new mixins.
182-
for (i = 0; i < this.states.length; i++) {
183-
for (j = 0; j < newMixinIds.length; j++) {
184-
this.registerMixin(newMixinIds[j] + '-' + this.states[i]);
185-
}
186-
}
187-
}
188-
},
189-
190133
getObject3D: {
191134
value: function (type) {
192135
return this.object3DMap[type];
@@ -668,7 +611,6 @@ var proto = Object.create(ANode.prototype, {
668611
value: function (newMixins, oldMixins) {
669612
oldMixins = oldMixins || this.getAttribute('mixin');
670613
this.updateMixins(newMixins, oldMixins);
671-
this.updateStateMixins(newMixins, oldMixins);
672614
this.updateComponents();
673615
}
674616
},
@@ -823,8 +765,7 @@ var proto = Object.create(ANode.prototype, {
823765
value: function (state) {
824766
if (this.is(state)) { return; }
825767
this.states.push(state);
826-
this.mapStateMixins(state, bind(this.registerMixin, this));
827-
this.emit('stateadded', {state: state});
768+
this.emit('stateadded', state);
828769
}
829770
},
830771

@@ -833,8 +774,7 @@ var proto = Object.create(ANode.prototype, {
833774
var stateIndex = this.states.indexOf(state);
834775
if (stateIndex === -1) { return; }
835776
this.states.splice(stateIndex, 1);
836-
this.mapStateMixins(state, bind(this.unregisterMixin, this));
837-
this.emit('stateremoved', {state: state});
777+
this.emit('stateremoved', state);
838778
}
839779
},
840780

0 commit comments

Comments
 (0)