Fix the use of MobX in playground (#5294)
* Register new playground component onMount * No need of observer * Fix tests
This commit is contained in:
parent
1ca1a4b1cc
commit
a12583f762
@ -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);
|
||||
}
|
||||
}
|
||||
|
@ -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);
|
||||
});
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user