state
, actions
and libraries
belong to a shared space among all packages, so each package needs to use its own namespace.wp-comments
(native WordPress comments) or disqus-comments
(Disqus comments) in your Frontity project because the theme is going to access it using the common comments
namespace and everything is going to work. In the future, another person could create a third comments
package, based on a new service, and as long as it respects the same structure (written in TypeScript), all the themes (even the old ones!) will work perfectly.source
: for example wp-source
, wpgrahql-source
or even drupal-source
β¦analytics
: for example google-analytics
, gtm-analytics
, mixpanel-analytics
β¦notifications
: for example onesignal-notifications
, pushwoosh-notifications
β¦share
: for example modal-share
, native-share
β¦router
: for example tiny-router
, 3d-router
β¦theme
package:roots
, state
, and actions
have a namespace called theme
. It may seem like it is not adding much value because it is the only namespace. Why not write it like this instead?comments
@frontity/wp-comments
package which has an actions.comments.submit
method. As you can see this method is defined under the comments
namespace.@frontity/wp-comments
package the actions.comments.submit
is responsible for sending the content of the fields in the comment form to WordPress.theme
packages that want to submit a comments form can check if there is a package with the comments
namespace with an actions.comments.submit
method available. If there is, it can be used from any React component in the project to submit comment form data.frontity.settings.js
to install and configure wp-comments
:disqus-comments
package instead:disqus-comments
package might define a different implementation of actions.comments.submit
that instead of submitting the comment form data to WordPress it would instead submit it to be handled by Disqus.theme
has no idea about what specific implementation of comments
you have installed. Everything works and the theme didn't need to change.analytics
analytics
namespace. All the packages that want to implement analytics need to have these two actions:actions.analytics.sendPageview
: send a pageview to the analytics service.actions.analytics.sendEvent
: send an event to the analytics service.actions.analytics.sendPageview
, is used by packages that implement router
, each time actions.router.set
is used.actions.analytics.sendEvent
, is used by the theme when something interesting happens. For example:analytics
package that is installed in the Frontity project, no matter which one it is ππ