mirror of
https://github.com/qlik-oss/nebula.js.git
synced 2025-12-19 17:58:43 -05:00
fix: instead add emitter in Cell (#1718)
* fix: instead add emitter in Cell * chore: better state handling Co-authored-by: Tobias Linsefors <T-Wizard@users.noreply.github.com> * chore: createEmitter properly --------- Co-authored-by: Tobias Linsefors <T-Wizard@users.noreply.github.com>
This commit is contained in:
@@ -1,5 +1,6 @@
|
|||||||
/* eslint-disable react/jsx-props-no-spreading */
|
/* eslint-disable react/jsx-props-no-spreading */
|
||||||
import React, { forwardRef, useImperativeHandle, useEffect, useState, useContext, useReducer, useRef } from 'react';
|
import React, { forwardRef, useImperativeHandle, useEffect, useState, useContext, useReducer, useRef } from 'react';
|
||||||
|
import EventEmitter from 'node-event-emitter';
|
||||||
|
|
||||||
import { Grid, Paper } from '@mui/material';
|
import { Grid, Paper } from '@mui/material';
|
||||||
import { useTheme } from '@nebula.js/ui/theme';
|
import { useTheme } from '@nebula.js/ui/theme';
|
||||||
@@ -312,6 +313,10 @@ const loadType = async ({
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
function createEmitter() {
|
||||||
|
return new EventEmitter();
|
||||||
|
}
|
||||||
|
|
||||||
const Cell = forwardRef(
|
const Cell = forwardRef(
|
||||||
(
|
(
|
||||||
{
|
{
|
||||||
@@ -337,6 +342,7 @@ const Cell = forwardRef(
|
|||||||
keyboardNavigation,
|
keyboardNavigation,
|
||||||
disableCellPadding = false,
|
disableCellPadding = false,
|
||||||
} = useContext(InstanceContext);
|
} = useContext(InstanceContext);
|
||||||
|
const [internalEmitter] = useState(emitter || createEmitter);
|
||||||
const theme = useTheme();
|
const theme = useTheme();
|
||||||
const [cellRef, cellRect, cellNode] = useRect();
|
const [cellRef, cellRect, cellNode] = useRect();
|
||||||
const [state, dispatch] = useReducer(contentReducer, initialState(initialError));
|
const [state, dispatch] = useReducer(contentReducer, initialState(initialError));
|
||||||
@@ -436,7 +442,7 @@ const Cell = forwardRef(
|
|||||||
selections,
|
selections,
|
||||||
nebbie,
|
nebbie,
|
||||||
focusHandler: focusHandler.current,
|
focusHandler: focusHandler.current,
|
||||||
emitter,
|
emitter: internalEmitter,
|
||||||
onMount,
|
onMount,
|
||||||
navigation,
|
navigation,
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
import React, { useEffect, useState, useContext, useMemo, forwardRef, useImperativeHandle, useRef } from 'react';
|
import React, { useEffect, useState, useContext, useMemo, forwardRef, useImperativeHandle, useRef } from 'react';
|
||||||
import EventEmitter from 'node-event-emitter';
|
|
||||||
import useLayout from '../hooks/useLayout';
|
import useLayout from '../hooks/useLayout';
|
||||||
import getObject from '../object/get-object';
|
import getObject from '../object/get-object';
|
||||||
import Cell from './Cell';
|
import Cell from './Cell';
|
||||||
@@ -28,8 +27,6 @@ function getCellRenderer(cell, halo, initialSnOptions, initialSnPlugins, initial
|
|||||||
style.padding = '4px';
|
style.padding = '4px';
|
||||||
}
|
}
|
||||||
|
|
||||||
const emitter = new EventEmitter();
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div style={style} key={cell.model.id}>
|
<div style={style} key={cell.model.id}>
|
||||||
<Cell
|
<Cell
|
||||||
@@ -41,7 +38,6 @@ function getCellRenderer(cell, halo, initialSnOptions, initialSnPlugins, initial
|
|||||||
initialSnPlugins={initialSnPlugins}
|
initialSnPlugins={initialSnPlugins}
|
||||||
initialError={initialError}
|
initialError={initialError}
|
||||||
onMount={onMount}
|
onMount={onMount}
|
||||||
emitter={emitter}
|
|
||||||
navigation={navigation}
|
navigation={navigation}
|
||||||
onError={onError}
|
onError={onError}
|
||||||
/>
|
/>
|
||||||
|
|||||||
Reference in New Issue
Block a user