Cogs – Reusable Components

In the previous five chapters of this book, we focused on developing functionality for either a specific web page on IGWEB or a specific feature, such as the live chat feature that we implemented in the last chapter. The solutions that we've made thus far have served a particular individual purpose. Not much consideration was factored into promoting code reuse for a particular user interface feature, since we didn't have the need to create multiple instances of it.

Reusable components are user interface widgets that provide a means to promote greater reusability. They can be used in a plug and play manner, since each component is a standalone user interface widget that contains its own set of Go source files and static assets, such as Go template files, along with CSS and JavaScript source files.

In this chapter, we will focus on creating cogs—reusable components that can be utilized in Isomorphic Go web applications. The term cog stands for component object in Go. Cogs are reusable user interface widgets that can either be implemented exclusively in Go (a pure cog) or implemented using Go and JavaScript (a hybrid cog).

We can create multiple instances of a cog and control the cog's behavior by supplying input parameters (in the form of key-value pairs) to the cog, known as props. When subsequent changes are made to the props, the cog is reactive, meaning that it can automatically re-render itself. Therefore, cogs have the capability to change their appearance, based on changes made to their props.

Perhaps, the most attractive feature of cogs is that they are readily reusable. Cogs are implemented as standalone Go packages that contain one or more Go source files along with any static assets that are needed by the cog's implementation.

In this chapter, we will cover the following topics:

  • Essential cog concepts
  • Implementing pure cogs
  • Implementing hybrid cogs
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.218.45.80