-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* added PlayerProvider and withPlayer components that expose player as prop to components * added EventDispatcher and withEventDispatcher components that inject EventDispatcher actions from context to props of a component * added withLogger component that inject logger as props of a component with a supplied namespace * added withEventManager component that inject event manager as props of a component that require to manage event listeners * fixed withAnimtation HoC signature to be inline with rest of HoCs *moved `shouldRender` to be internal in component - this is cause HoCs don't expose static methods and in general this is not the best way to do it if we need to be able to dynamically add and remove components from bundle * updated all indices of the player to use the new HoCs * added doc
- Loading branch information
Showing
76 changed files
with
1,868 additions
and
1,025 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,8 @@ | ||
# Guides | ||
|
||
* [Create UI Component](./create-ui-component.md) | ||
* [Customizing the Player CSS](./css-classes-override.md) | ||
* [Custom UI Preset](./custom-ui-preset.md) | ||
* [Inject UI Component](./ui-components.md) | ||
## Customizing the UI look-and-feel | ||
* [UI customization](./ui-customization.md) | ||
|
||
## Services and Events | ||
* [UI manager services as HoC containers](./ui-manager-services.md) | ||
* [Supported UI events](./events.md) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
# UI manager services | ||
|
||
The UI manager tries to separate concerns by allowing UI components to handle the presentational aspects. | ||
In order to enable advanced use cases the manager exposes services as HoC that can inject those service to the component | ||
without it having to take care of initialization or cleanup of the services. | ||
The available services are: | ||
* [withPlayer](./with-player.md) - exposes player instance to the component | ||
* [withLogger](./with-logger.md) - exposes logger instance to the component | ||
* [withEventManager](./with-logger.md) - exposes event manager instance to the component |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,143 @@ | ||
## Using an event manager in your component | ||
|
||
### withEventManager HoC | ||
|
||
If your components requires to listen to events then UI supplies an event manager as a service. | ||
The event manager provides encapsulation over the document native event system, taking care of managing event registry per event and target and cleaning event listeners and upon component unmount to avoid memory leaks via the HoC. | ||
In addition, the player, which is exposed via the [`withPlayer`](./with-player.md) HoC, is compatible as an event target that the event manager requires. | ||
The HoC exposes the event manager to the wrapped component and will be accessible via the component props, i.e. `this.props.eventManager`. | ||
Events can be added by `this.props.eventManager.listen(EVENT_TARGET, EVENT_NAME, EVENT_HANDLER)` or `listenOnce` which removes listener after first occurrence of the event. | ||
|
||
Let's see an example, building on the [`withPlayer`](./with-player.md) sample: | ||
|
||
> This sample will add a player `playing` event listener and prints it out to console when it is triggered. | ||
```javascript | ||
const h = KalturaPlayer.ui.h; | ||
const withPlayer = KalturaPlayer.ui.components.withPlayer; | ||
const withEventListener = KalturaPlayer.ui.components.withEventListener; | ||
const Component = KalturaPlayer.ui.preact.Component; | ||
|
||
class SampleComponent extends Component { | ||
componentDidMount() { | ||
this.props.eventManager.addEventListener( | ||
this.props.player, | ||
'playing', | ||
() => {console.info('playing')} | ||
); | ||
} | ||
|
||
componentWillUnount() { | ||
// free resources here | ||
} | ||
|
||
render(props) { | ||
return h( | ||
'div', | ||
{ | ||
className: 'dumb-component', | ||
style: { | ||
width: '40px', | ||
height: '40px', | ||
backgroundColor: 'red' | ||
}, | ||
onClick: () => { | ||
console.info(this.props.player.currentTime); | ||
} | ||
}, | ||
props.children | ||
); | ||
} | ||
} | ||
|
||
export default withEventListener(withPlayer(SampleComponent)); | ||
``` | ||
|
||
If you want to use JSX follow this [guide](./custom-ui-preset.md#using-jsx), and use following JSX syntax: | ||
|
||
```javascript | ||
const h = KalturaPlayer.ui.h; | ||
const withPlayer = KalturaPlayer.ui.components.withPlayer; | ||
const withEventListener = KalturaPlayer.ui.components.withEventListener; | ||
const Component = KalturaPlayer.ui.preact.Component; | ||
|
||
class DumbComponent extends Component { | ||
componentDidMount() { | ||
this.props.eventManager.addEventListener( | ||
this.props.player, | ||
'playing', | ||
() => {console.info('playing')} | ||
); | ||
} | ||
render(props) { | ||
return <div | ||
className="dumb-component" | ||
style= {{ | ||
width: '40px', | ||
height: '40px', | ||
backgroundColor: 'red' | ||
}} | ||
onClick = {() => { | ||
console.info(this.props.player.currentTime); | ||
}} | ||
> | ||
{props.children} | ||
</div>; | ||
} | ||
} | ||
|
||
export default withEventListener(withPlayer(DumbComponent)); | ||
``` | ||
|
||
And if you want to use it as a decorator: | ||
|
||
```javascript | ||
const h = KalturaPlayer.ui.h; | ||
const withPlayer = KalturaPlayer.ui.components.withPlayer; | ||
const withEventListener = KalturaPlayer.ui.components.withEventListener; | ||
const Component = KalturaPlayer.ui.preact.Component; | ||
|
||
@withPlayer | ||
@withEventListener | ||
class DumbComponent extends Component { | ||
componentDidMount() { | ||
this.props.eventManager.addEventListener( | ||
this.props.player, | ||
'playing', | ||
() => {console.info('playing')} | ||
); | ||
} | ||
render(props) { | ||
return <div | ||
className="dumb-component" | ||
style= {{ | ||
width: '40px', | ||
height: '40px', | ||
backgroundColor: 'red' | ||
}} | ||
onClick: {() => { | ||
console.info(this.props.player.currentTime); | ||
}} | ||
> | ||
{props.children} | ||
</div>; | ||
} | ||
} | ||
|
||
export default DumbComponent; | ||
``` | ||
|
||
The usage of this component will be: | ||
|
||
```javascript | ||
const h = KalturaPlayer.ui.h; | ||
h(DumbComponent, null, h('p', null, 'You can add here any components and html you want and it will be appended to the DumbComponent')); | ||
``` | ||
|
||
Or again, if using JSX: | ||
|
||
```html | ||
<DumbComponent> | ||
<p>You can add here any components and html you want and it will be appended to the DumbComponent</p> | ||
</DumbComponent> | ||
``` |
Oops, something went wrong.