Fix the use of MobX in playground (#5294)

* Register new playground component onMount

* No need of observer

* Fix tests
This commit is contained in:
Nicolas Gotchac 2017-03-27 17:27:35 +02:00 committed by Jaco Greeff
parent 1ca1a4b1cc
commit a12583f762
2 changed files with 2 additions and 20 deletions

View File

@ -14,12 +14,12 @@
// You should have received a copy of the GNU General Public License
// along with Parity. If not, see <http://www.gnu.org/licenses/>.
import { action, observable } from 'mobx';
import { action } from 'mobx';
let instance = null;
export default class PlaygroundStore {
@observable components = [];
components = [];
static get () {
if (!instance) {
@ -35,17 +35,6 @@ export default class PlaygroundStore {
@action
add (component) {
const name = component.type.displayName || component.type.name;
const hasComponent = this.components.find((c) => {
const cName = c.type.displayName || c.type.name;
return name && cName && cName === name;
});
if (hasComponent) {
return;
}
this.components.push(component);
}
}

View File

@ -31,11 +31,4 @@ describe('playground/store', () => {
PlaygroundStore.register(<QrCode />);
expect(store.components.length).greaterThan(0);
});
it('adds new Components only once', () => {
PlaygroundStore.register(<QrCode />);
PlaygroundStore.register(<QrCode />);
expect(store.components.filter((c) => /QrCode/i.test(c.type.name)).length).equal(1);
});
});