jschess is normal js app, but intended to use react like lifesycle, for mounting and updating components. For now only static is board is ready, click event and keystrokes is soon going to add.
The below describes how we are planing.
Include the following jschess.min.js or jschess.js in script tag
<script src="./dist/jschess.min.js"></script>And add the following html and js snippet in .html file
<div id = "test" style="width: 60rem;height: 60rem;">
</div>
<script>
$(document).ready(()=>{
var game = new Game(props = {id : "test"})
});
</script>You can get the demo here
You can change color of the board by config.set_black_white method in a script tag.
The below code set the color scheme to blue shades, you can play around to find your favriote combination
config.set_black_white({
black : "#0047b3",
white : "#e6f0ff"
})constructor():- The
constructor()method is called before anything else, when the component is initiated, and it is the natural place initial state and other initial values for Board, Game and Engine varibles are set.
- The
getDerivedStateFromProps():# we are not using this for now- The
getDerivedStateFromProps()method is called right before rendering the element, we are not using this for now
- The
render():- The
render()method is required, and is the method that actual outputs HTML Board.
- The
componentDidMount():- The
componentDidMount()method is called after the component is rendered. This is where you run statements that requires that the component is already placed in the board. It is useful for setting the optional things on board, example filling canvas by square names, etc.
- The
getDerivedStateFromProps():- It extract the meaningful data from the props, It can be used for props standardisation. We are not using this as of now.
shouldComponentUpdate()- In the
shouldComponentUpdate()method you can return a Boolean value that specifies whetherjschessshould continue with the rendering or not. The default value is true. This significanlt improves performance if not rendering the unchanged element. It is partially implemented.
- In the
rerender():- The
rerender()method is of course called when a component gets updated, it has to re-render the HTML to the board, with the new changes. It different from therenderby means render puts the things, and it updates the things.
- The
getSnapshotBeforeUpdate():- In the
getSnapshotBeforeUpdate()method you have access to the props and state before the update, meaning that even after the update, you can check what the values were before the update. Usefull in case you need to highligh the previous two moves. It will only store the previous state, so to have actual changes, you need to callcomponentDidUpdate.
- In the
componentDidUpdate():- The componentDidUpdate method is called after the component is updated in the board. Useful to set extra things, like if you want to highlight previous two moves.
jschess has utils.js which includes various different coding practices used, experimented while developing the jschess.
- It includes the
convertorclass which has only static methods, useful for different scale conversion to pixels, likevhtopixels, etc. getclass which has method to returned the full page height, width, or height and width of just a div- You can use
queryclass, if you want to query on object created, for that you need to just add any object created toobjectsby callingobjects.add(this), with this you can use query methods on object to find all particular class instances etc.
Will soon create the proper documentation regarding the message formats, method descriptions etc.