<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>Forem: Akshay Ram Vignesh</title>
    <description>The latest articles on Forem by Akshay Ram Vignesh (@akshay5995).</description>
    <link>https://forem.com/akshay5995</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F103695%2F67dbd706-ca23-4151-a39d-499c1b3f6f38.jpg</url>
      <title>Forem: Akshay Ram Vignesh</title>
      <link>https://forem.com/akshay5995</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/akshay5995"/>
    <language>en</language>
    <item>
      <title>useReport Hook and some thoughts on good API design for libraries</title>
      <dc:creator>Akshay Ram Vignesh</dc:creator>
      <pubDate>Sat, 16 May 2020 23:46:37 +0000</pubDate>
      <link>https://forem.com/akshay5995/usereport-hook-and-some-thoughts-on-good-api-design-for-libraries-503p</link>
      <guid>https://forem.com/akshay5995/usereport-hook-and-some-thoughts-on-good-api-design-for-libraries-503p</guid>
      <description>&lt;p&gt;This post covers how to embed your Microsoft PowerBi reports into your React application using _ &lt;strong&gt;useReport&lt;/strong&gt; _ hook from &lt;a href="https://github.com/akshay5995/powerbi-report-component"&gt;powerbi-report-component&lt;/a&gt;. I'll go into some depth of inner working of the package and rational behind &lt;code&gt;useReport&lt;/code&gt;, and some thoughts on good API design libraries.&lt;/p&gt;

&lt;p&gt;TLDR; if you just want to use &lt;code&gt;useReport&lt;/code&gt;, here's how it works.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import React, { useEffect, useRef } from "react"
import { useReport } from "powerbi-report-component"

// Some powerbi setting disable your nav and filters from embed
const settings = {
  filterPaneEnabled: false,
  navContentPaneEnabled: false,
}

const MyReport = () =&amp;gt; {
  const reportRef = useRef(null)
  // userReport returns `report` the embed instance and setEmbed a function to
  // set your embed into the div
  const [report, setEmbed] = useReport()

  const myReportConfig = {
    embedType: "report",
    tokenType: "Embed",
    accessToken: "", // your access token
    embedUrl: "", // your embed url
    embedId: "", // your embed Id
    settings,
  }

  // !important
  useEffect(() =&amp;gt; {
    // call inside useEffect so the we have the reportRef (reference available)
    // pass in the ref for the div and your config
    setEmbed(reportRef, myReportConfig)
  }, [])

  const handleclick = () =&amp;gt; {
    // you can use "report" from useReport like
    if (report) report.print()
  }

  return (
    &amp;lt;div className="report-container"&amp;gt;
      &amp;lt;div className="report" ref={reportRef} /&amp;gt;
      &amp;lt;button onClick={handleclick}&amp;gt;Print my report&amp;lt;/button&amp;gt;
    &amp;lt;/div&amp;gt;
  )
}

export default MyReport
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Now, for those interested in why &lt;code&gt;useReport&lt;/code&gt;hook and how it works.&lt;/p&gt;

&lt;p&gt;So, what do I mean by good API design?&lt;/p&gt;

&lt;p&gt;Let's first see what an API is. API is an acronym for Application Programming Interface. It is a software delegate that allows two applications to talk to each other. When we talk about APIs we are usually referring to REST API or HTTP endpoints.&lt;/p&gt;

&lt;p&gt;How does it apply to libraries?&lt;/p&gt;

&lt;p&gt;Functions or components exposed by your library are also APIs.As it allows the developer to communicate between their application code and your code that exists in the library.&lt;/p&gt;

&lt;p&gt;When I first created the component it allowed you to embed a report in your React application. So it exported React component as a default called &lt;code&gt;Report&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;The library user would've imported it and used it like:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import Report from "powerbi-report-component";

&amp;lt;Report
  embedType="report" // or "dashboard"
  ...{otherProps}
/&amp;gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;&lt;em&gt;(Note: Microsoft PowerBi actually supports multiple types of embeds: Report, Dashboard, Tile)&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;This made sense at that time. As it would be used to embed only an Microsoft PowerBi &lt;code&gt;Report&lt;/code&gt; not &lt;code&gt;Dashboard&lt;/code&gt; or &lt;code&gt;Tile&lt;/code&gt;. Soon I added &lt;code&gt;embedType&lt;/code&gt; as a prop to support embedding &lt;code&gt;Dashboard&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;This felt a little odd when you're actually embedding a &lt;code&gt;dashboard&lt;/code&gt; and you still had to use a &lt;code&gt;&amp;lt;Report /&amp;gt;&lt;/code&gt; and pass &lt;code&gt;dashboard&lt;/code&gt; to &lt;code&gt;embedType&lt;/code&gt; prop inside your code.&lt;/p&gt;

&lt;p&gt;Also, using &lt;code&gt;embedType&lt;/code&gt; to determine what kind of props can be passed to the component made the library code bloated and less clean with the use of switch is multiple places.&lt;/p&gt;

&lt;p&gt;Soon I started getting feature requests to support &lt;em&gt;Tile&lt;/em&gt; and for &lt;em&gt;Create Report&lt;/em&gt; feature.&lt;/p&gt;

&lt;p&gt;Each embed type had to support a lot more handlers and other properties.&lt;/p&gt;

&lt;p&gt;For example, You can have handler &lt;code&gt;onPageChange&lt;/code&gt; handler on &lt;code&gt;embedType = report&lt;/code&gt; but not in &lt;code&gt;embedType = dashboard&lt;/code&gt; or &lt;code&gt;embedType = tile&lt;/code&gt; or, You can have a &lt;code&gt;pageView&lt;/code&gt; prop for &lt;code&gt;embedType = dashboard&lt;/code&gt; but not for &lt;code&gt;embedType = report&lt;/code&gt; or&lt;code&gt;embedType = tile&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;But, the library just exported a single component (&lt;code&gt;Report&lt;/code&gt;) and &lt;code&gt;propTypes&lt;/code&gt; of the component looked like this.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Report.propTypes = {
  embedType: PropTypes.string.isRequired,
  tokenType: PropTypes.string.isRequired,
  accessToken: PropTypes.string.isRequired,
  embedUrl: PropTypes.string.isRequired,
  embedId: PropTypes.string,
  pageName: PropTypes.string,
  extraSettings: PropTypes.object,
  permissions: PropTypes.string,
  onLoad: PropTypes.func,
  onError: PropTypes.func,
  onSelectData: PropTypes.func,
  onPageChange: PropTypes.func,
  onTileClicked: PropTypes.func,
  style: PropTypes.object,
  reportMode: PropTypes.string,
  datasetId: PropTypes.string,
}
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;React component is nothing but a &lt;code&gt;function&lt;/code&gt; and props are nothing but &lt;code&gt;parameters&lt;/code&gt; that you pass in to the function. This means that &lt;code&gt;Report&lt;/code&gt; is one function that you can pass _ &lt;strong&gt;16&lt;/strong&gt; _ parameters into. Library user can never actually know which parameter to pass in unless they go and see the documentation every time they had to make a change.&lt;/p&gt;

&lt;p&gt;User's IDE intellisense also becomes useless as suggestions will have _ &lt;strong&gt;16&lt;/strong&gt; _ props instead of only right props for their use case.&lt;/p&gt;

&lt;p&gt;This parameter list was only going to increase in number as I keep adding new handlers or properties based on feature requests. Exporting a single &lt;code&gt;default export&lt;/code&gt; of a &lt;code&gt;Report&lt;/code&gt; also was not maintainable.&lt;/p&gt;

&lt;p&gt;This is an example of a _ &lt;strong&gt;bad&lt;/strong&gt; _ API design. As it doesn't compliment the users development environment like the IDE or doesn't help speed the user's workflow.&lt;/p&gt;

&lt;p&gt;Having the &lt;code&gt;embedType&lt;/code&gt; as a prop creates confusion here as the user might be using library to embed a &lt;code&gt;Tile&lt;/code&gt; but would still be using it as &lt;code&gt;Report&lt;/code&gt; in their code.&lt;/p&gt;

&lt;p&gt;With this in mind. Maintainers and I went ahead refactored the code to export multiple components as named exports. i.e, &lt;code&gt;Report&lt;/code&gt;, &lt;code&gt;Dashboard&lt;/code&gt; and &lt;code&gt;Tile&lt;/code&gt; with their respective props. Now we have multiple named exports based on &lt;code&gt;embedType&lt;/code&gt; which can be imported like. This also made the library code more maintainable.&lt;/p&gt;

&lt;p&gt;Now the library can be used like.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import { Tile, Dashboard, Report } "powerbi-report-component";
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;And the &lt;code&gt;propTypes&lt;/code&gt; of respective exports look like:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Report.propTypes = {
  tokenType: PropTypes.string.isRequired,
  accessToken: PropTypes.string.isRequired,
  embedUrl: PropTypes.string.isRequired,
  embedId: PropTypes.string,
  pageName: PropTypes.string,
  extraSettings: PropTypes.object,
  permissions: PropTypes.string,
  style: PropTypes.object,
  reportMode: PropTypes.string,
  datasetId: PropTypes.string,
  onLoad: PropTypes.func,
  onRender: PropTypes.func,
  onError: PropTypes.func,
  onButtonClicked: PropTypes.func,
  onSelectData: PropTypes.func,
  onPageChange: PropTypes.func,
  onCommandTriggered: PropTypes.func,
}

Dashboard.propTypes = {
  tokenType: PropTypes.string.isRequired,
  accessToken: PropTypes.string.isRequired,
  embedUrl: PropTypes.string.isRequired,
  embedId: PropTypes.string.isRequired,
  pageView: PropTypes.string,
  style: PropTypes.object,
  onLoad: PropTypes.func,
  onTileClicked: PropTypes.func,
}

Tile.propTypes = {
  tokenType: PropTypes.string.isRequired,
  accessToken: PropTypes.string.isRequired,
  embedUrl: PropTypes.string.isRequired,
  embedId: PropTypes.string.isRequired,
  dashboardId: PropTypes.string.isRequired,
  style: PropTypes.object,
  onLoad: PropTypes.func,
  onClick: PropTypes.func,
}
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;This enables the user to use the library without having to go back and see the docs every time and IDE intellisense will suggest the right props which speeds up the developer's workflow and the user doesn't have to go to see the docs every time they had to make a change.&lt;/p&gt;

&lt;p&gt;Since, We made the exports from the library more explicit. User will be able use &lt;code&gt;Tile&lt;/code&gt; in the place where they are embedding &lt;code&gt;Tile&lt;/code&gt; or &lt;code&gt;Dashboard&lt;/code&gt; when they want to embed a &lt;code&gt;Dashboard&lt;/code&gt;. This solves a lot of confusion and is explicit enough to make sense where it's used in your codebase.&lt;/p&gt;

&lt;p&gt;A _ &lt;strong&gt;good&lt;/strong&gt; _ API design for libraries has to get these right:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Complement the tools available in the end user's development environment.&lt;/li&gt;
&lt;li&gt;Explicit enough to make sense where it's used.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;One way to compliment the user's development environment is enabling IDE intellisense to speed up user's workflow. i.e, by making _ &lt;strong&gt;exports explicit&lt;/strong&gt; _ or using right &lt;code&gt;propTypes&lt;/code&gt; like what you just saw.&lt;/p&gt;

&lt;p&gt;Another way would be to support multiple ways to use your library based on user's development environment.&lt;/p&gt;

&lt;p&gt;The library supported embedding your reports using components by exposing React components. This is one way of sharing code or using the API.&lt;/p&gt;

&lt;p&gt;Now, React has hooks to share code. (Read more about it &lt;a href="https://reactjs.org/docs/hooks-intro.html"&gt;here&lt;/a&gt;)&lt;/p&gt;

&lt;p&gt;I refactored the library to use the React hooks and it internally looked like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// private used inside the library to embed
function _useReport(performOnEmbed = null) {
  // store the embed instance
  const [report, _setEmbedInstance] = useState(null)

  const setEmbed = (embedDivRef, embedConfig) =&amp;gt; {
    // validate your configuration passed as props
    const errors = validateConfig(embedConfig)
    if (!errors) {
      embed(embedDivRef.current, embedConfig)
    } else {
      throw new Error("invalid configuration passed")
    }
  }

  const embed = (ref, config) =&amp;gt; {
    const { reportMode } = config
    // check reportMode
    const isCreateMode = reportMode === "create"
    let embedInstance

    // call the right powerbi library method
    if (isCreateMode) embedInstance = powerbi.createReport(ref, config)
    else {
      embedInstance = powerbi.embed(ref, config)
    }

    if (performOnEmbed) {
      // add handlers to the embedInstance that are passed as props
      // like onPageChange, onSelectData, etc..
      performOnEmbed(embedInstance, ref)
    }

    // set the embed instance in the state
    _setEmbedInstance(embedInstance)
  }

  // expose embed instance and a method to embed
  return [report, setEmbed]
}
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Since, React now enables sharing of code as a hook. I can remove a lot of library specific code and expose this hook for the end user.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// cleaner and a default API to export
function useReport() {
  const [report, _setEmbedInstance] = useState(null)

  const setEmbed = (ref, config) =&amp;gt; {
    // create config based on embedType
    const embedConfig = createEmbedConfigBasedOnEmbedType(config)
    // validate the config
    const errors = validateConfig(embedConfig)
    if (!errors) {
      embed(ref.current, embedConfig)
    } else {
      throw new Error("invalid configuration passed")
    }
  }

  const embed = (ref, config) =&amp;gt; {
    const embedInstance = powerbi.embed(ref, config)
    _setEmbedInstance(embedInstance)
  }

  // expose instance and method to embed
  return [report, setEmbed]
}
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;See the full code &lt;a href="https://github.com/akshay5995/powerbi-report-component/blob/master/src/lib/hooks/useReport.js"&gt;here&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;By exporting &lt;code&gt;useReport&lt;/code&gt; from the library the user has more than one way to use the library. This adds to the value of the library as it complements the users development environment by the use React hooks.&lt;/p&gt;

&lt;p&gt;The hook exposes an internal function as an API for end user to get the most out of the library and by using the hook user can choose to reduce the extra abstraction and logic that comes along with using the API with an component.&lt;/p&gt;

&lt;p&gt;This was the rationale behind the &lt;code&gt;useReport&lt;/code&gt; hook and my thoughts on good API design for libraries.&lt;/p&gt;

&lt;p&gt;Next step in the quest to improve the API design for the library would be add typings and support types. i.e, to add support for Typescript (In progress). In the next post I'll cover some basics of Typescript and more on migrating the library to Typescript.&lt;/p&gt;

&lt;p&gt;If you're interested seeing more of the code you can head here: &lt;a href="https://github.com/akshay5995/powerbi-report-component/"&gt;https://github.com/akshay5995/powerbi-report-component/&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;PRs or issues welcome for the library.&lt;/p&gt;

&lt;p&gt;Thanks for your time!&lt;/p&gt;

</description>
      <category>powerbi</category>
      <category>reacthooks</category>
      <category>libraries</category>
    </item>
    <item>
      <title>Redux - Predictive state management on the client side</title>
      <dc:creator>Akshay Ram Vignesh</dc:creator>
      <pubDate>Sun, 30 Jun 2019 23:46:37 +0000</pubDate>
      <link>https://forem.com/akshay5995/redux-predictive-state-management-on-the-client-side-2a1d</link>
      <guid>https://forem.com/akshay5995/redux-predictive-state-management-on-the-client-side-2a1d</guid>
      <description>&lt;p&gt;Hi guys, It’s been a &lt;em&gt;really long&lt;/em&gt; time since I wrote a blog post. I’m starting a habit of regularly blogging about the things I learn. I plan to blog about both technical and non-technical subjects.&lt;/p&gt;

&lt;p&gt;Without any further ado.&lt;/p&gt;

&lt;p&gt;Redux is a state management library for javascript applications. It comes in handy in projects where state management becomes too complicated or state gets difficult to keep track. Redux helps us by making the state predictable, centralized, debuggable and flexible.&lt;/p&gt;

&lt;p&gt;Let’s get into the details of what those mean in a minute. Let’s look at the Flux architecture first. You might be thinking, &lt;em&gt;“Flux? Why?&lt;/em&gt;” .&lt;/p&gt;

&lt;p&gt;It’s really important as Redux was inspired by the Flux architecture. Bear with me.&lt;/p&gt;

&lt;h2&gt;
  
  
  Flux
&lt;/h2&gt;

&lt;p&gt;Flux is a pattern for handling data in your application. Flux and React grew up together in Facebook. Just like Redux, Flux and React are mostly used together in applications even though they can be used independently.&lt;/p&gt;

&lt;p&gt;Flux was created to fix a very specific problem at the time in facebook. I highly recommend you read this amazing intro to &lt;a href="https://code-cartoons.com/a-cartoon-guide-to-flux-6157355ab207"&gt;Flux by Lin Clark&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Flux and Redux are fundamently very similar. You can’t directly mutate the store without firing an action.&lt;/p&gt;

&lt;p&gt;The underlying problem they were trying to solve at facebook was the way dat flowed through the application.&lt;/p&gt;

&lt;p&gt;They had models which held the data and would pass data to the view layer to render the data. There were several scenarios by which your model can get updated. An user interaction can update the model or, a model can update another model. There were even complex scenarios where cascading updates. Lin in here article makes an analogy of “Throwing a whole bag of ping-pong balls into your Pong game, with them flying all over the place and crossing paths”. There updates also happened asynchronously. This made things very hard for debugging.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Solution&lt;/em&gt; : &lt;em&gt;Unidirectional Data Flow&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Facebook came up with this unidirectional data flow architecture where data flow only in one directi. And, they called it &lt;em&gt;Flux&lt;/em&gt;.&lt;/p&gt;

&lt;p&gt;This is what data flow in flux looks like:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--OtLx2dja--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://facebook.github.io/flux/img/flux-simple-f8-diagram-with-client-action-1300w.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--OtLx2dja--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://facebook.github.io/flux/img/flux-simple-f8-diagram-with-client-action-1300w.png" alt="Flux data flow"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;I’ll not go deeper into Flux in this article as it’s about Redux. I highly recommend that you to read about the flux architecture.&lt;/p&gt;

&lt;p&gt;Now back to Redux.&lt;/p&gt;

&lt;p&gt;Redux was inspired by Flux architecture. Dan Abramov wanted to improve flux. He wanted to make better tooling around the state management ecosystem and make it extensible. (like, &lt;a href="https://www.youtube.com/watch?v=xsSnOQynTHs"&gt;Time travel debugging&lt;/a&gt;).&lt;/p&gt;

&lt;p&gt;According to official Redux's official site. Redux can be explained using the follwing &lt;a href="(http://redux.js.org/docs/introduction/ThreePrinciples.html)"&gt;Principles&lt;/a&gt;.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Single Soure of truth.&lt;/li&gt;
&lt;li&gt;State is read only.&lt;/li&gt;
&lt;li&gt;Changes are made with pure functions&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Redux is made up of the following entities:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Action creators&lt;/li&gt;
&lt;li&gt;Reducers&lt;/li&gt;
&lt;li&gt;Store&lt;/li&gt;
&lt;li&gt;View i.e, Smart and Dumb components&lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;
  
  
  The store
&lt;/h3&gt;

&lt;p&gt;&lt;em&gt;I. Single source of truth&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;The store is the data store a place store all your information. By definition of First Principle. The store is the single source of truth for your application.&lt;/p&gt;

&lt;h3&gt;
  
  
  Reducers
&lt;/h3&gt;

&lt;p&gt;&lt;em&gt;II. State is read only&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;“To specify how the state tree is transformed by actions, you write pure reducers.”&lt;/p&gt;

&lt;p&gt;Reducers are &lt;em&gt;pure functions&lt;/em&gt; that take the previous state of the app and return a new state based on the action passed to it.&lt;/p&gt;

&lt;p&gt;They look something like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const initialState = {}

const myReducer = (state = initialState, action) =&amp;gt; {
  switch (action.type) {
    case "ADD_TODO": {
      const { id, todo } = payload
      return { ...state, [id]: todo }
    }
  }
}
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;h3&gt;
  
  
  Action creators
&lt;/h3&gt;

&lt;p&gt;Actions are events that happen in your application which can change in your model (store). They are the only way you can send data from your application to your Redux store.&lt;/p&gt;

&lt;p&gt;Actions are plain JavaScript objects and they must have a type property to indicate the &lt;em&gt;type&lt;/em&gt; of action to be carried out. They must also have a &lt;em&gt;payload&lt;/em&gt; that contains the information that should to worked on by the action.&lt;/p&gt;

&lt;p&gt;Actions have this signature:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;{
  type: "UPDATE_MY_STORE",
  payload: {
    "dummy": "data"
  }
}
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Actions are created by functions called &lt;em&gt;Action creators&lt;/em&gt;. They look something like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const signIn = (username. password) =&amp;gt; {
  return({
    type: types.SIGN_IN,
    payload: {
      username,
      password
    }
  });
}
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;&lt;em&gt;III. Changes are made with pure functions&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;We dispatch these action using the store's function and the Reducer (a &lt;em&gt;pure function&lt;/em&gt;) receive's this action and current state and gives us the &lt;em&gt;new state&lt;/em&gt;.&lt;/p&gt;

&lt;h3&gt;
  
  
  Views (Smart and Dumb)
&lt;/h3&gt;

&lt;p&gt;Views are just the components that subscribe to the store.&lt;/p&gt;

&lt;p&gt;Smart components = &lt;em&gt;Containers&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Dumb Components = &lt;em&gt;Presentational Components&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Smart components can be though of as an inteface between your Redux store and the Dumb components. They only deal with the subscription and passing down of actions and/or state from the store to the Dumb components. Do not email any DOM of their own.&lt;/p&gt;

&lt;p&gt;Dumb components are purely responsible for rendering the DOM. Hence are called Presentational Components. They receive the actions and state as props passed to them by the container components.&lt;/p&gt;

&lt;p&gt;This distinction is an important pattern followed as a standard across most projects you'll come across. &lt;a href="https://medium.com/@dan_abramov/smart-and-dumb-components-7ca2f9a7c7d0"&gt;Read more&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;These are some important points to remember when you work with redux:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;The only way a user should be able to mutate state is through actions.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Reducers are pure functions in a state tree. Your app’s state properties are each represented by a function that provides updates to their state. Each reducer is unique to each state property and vice versa.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;The store is singular and contains the entire state of the app. When we use it this way, we can track each and every change to the state of the app.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Reducers can be thought of as behavioral definitions of state tree properties.&lt;/p&gt;

&lt;p&gt;If you're building a small application I suggest you use React's component state or the new Context API to share state among your components. Don't make &lt;em&gt;Redux&lt;/em&gt; your defacto state management tool for all your React apps or projects.&lt;/p&gt;

&lt;p&gt;(Tradeoffs) Redux asks you to:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Describe application state as plain objects and arrays.&lt;/li&gt;
&lt;li&gt;Describe changes in the system as plain objects.&lt;/li&gt;
&lt;li&gt;Describe the logic for handling changes as pure functions.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Okay, You don't have to take my word for it. Instead, &lt;a href="'https://medium.com/@dan_abramov/you-might-not-need-redux-be46360cf367"&gt;believe Dan&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;There are &lt;em&gt;tradeoffs&lt;/em&gt; in any solution you pick so choose wisely by carefully analysing your use case and the list of available solutions. I always recommend starting with something minimal and moving to something advanced when you hit a roadblock.&lt;/p&gt;

&lt;p&gt;If you're interested in how redux works under the hood. I highly recommend you try implementing Redux from &lt;a href="https://www.jamasoftware.com/blog/lets-write-redux/"&gt;scratch&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Hope I this article was worth your time. Thank you for reading :)&lt;/p&gt;

</description>
      <category>react</category>
      <category>redux</category>
      <category>javascript</category>
    </item>
    <item>
      <title>React's Context API By Implementing a Simple Snack Bar</title>
      <dc:creator>Akshay Ram Vignesh</dc:creator>
      <pubDate>Sat, 15 Sep 2018 23:46:37 +0000</pubDate>
      <link>https://forem.com/akshay5995/react-s-context-api-by-implementing-a-simple-snack-bar-190m</link>
      <guid>https://forem.com/akshay5995/react-s-context-api-by-implementing-a-simple-snack-bar-190m</guid>
      <description>&lt;p&gt;In React, data is passed top-down (parent to child) via props, but this can be cumbersome for certain types of data that is required by many components within an application. Context provides a way to share values like these between components without having to explicitly pass a prop through every level of the tree.&lt;/p&gt;

&lt;p&gt;I'm sure we all have had requirement where we had to implement snack bar for our react application. I'll be showing you how to implement simple snack bar using the React's Context API in this article. Little background before we dive deep. The Context API before React 16.3 was available as an experimental API. Now it's not experimental anymore and has been shipped as a part of React 16.3+ versions for quite some time. The goal of the article is to build a minimal Snack Bar component and to understand how to use the Context API and it's use case.&lt;/p&gt;

&lt;p&gt;This is a more complex example than the one provided in the official documentation. Context is designed to share data that can be considered "global" for a tree of React components. Here in our example we'll be using context to pass down data and handler functions that's needed to control opening/closing our SnackBar anywhere inside your app and as well as data needed for our SnackBar. Let's use create-react-app to bootstrap a new app called react-context-demo.&lt;/p&gt;

&lt;p&gt;File names are provided in comments above every snippet use the same to create files accordingly.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;createContext&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;/* file: SnackBarContext.jsx */

// Default State of our SnackBar
const DEFAULT_STATE = {
  show: false, // boolean to control show/hide
  displayText: "", // text to be displayed in SnackBar
  timeOut: 2000, // time SnackBar should be visible
};

// Create our Context
const SnackBarContext = React.createContext(DEFAULT_STATE);
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;The created context(SnackBarContext) has properties { Provider, Consumer }.When React renders a context Consumer, it will read the current context value from the closest matching Provider above it in the tree.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Provider&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;Provider value={/* some value */} /&amp;gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;A React component that allows Consumers to subscribe to context changes. It accepts a &lt;em&gt;value&lt;/em&gt; to be passed on to Consumers that are descendants of this Provider.&lt;/p&gt;

&lt;p&gt;Now Let's create a Provider called &lt;em&gt;SnackBarProvider&lt;/em&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;/* file: SnackBarContext.jsx */

export class SnackBarProvider extends PureComponent {
  constructor(props) {
    super(props)
    // DEFAULT_STATE defined earlier
    this.state = Object.assign({}, DEFAULT_STATE)
    this.handleClose = this.handleClose.bind(this)
    this.handleOpen = this.handleOpen.bind(this)
  }
  handleOpen(displayText) {
    // Show the SnackBar with 'displayText'
    this.setState({
      show: true,
      displayText,
    })
    setTimeout(
      // To hide SnackBar after 2s
      () =&amp;gt; this.setState({ show: false }),
      this.state.timeOut
    )
  }
  handleClose() {
    // Show the SnackBar with 'displayText'
    this.setState({
      show: false,
      displayText: "",
    })
  }
  render() {
    return (
      &amp;lt;SnackBarContext.Provider
        value={{
          ...this.state,
          handleOpen: this.handleOpen,
          handleClose: this.handleClose,
        }}
      &amp;gt;
        {this.props.children}
      &amp;lt;/SnackBarContext.Provider&amp;gt;
    )
  }
}
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;The &lt;em&gt;SnackBarProvider&lt;/em&gt; will be a stateful component which will return it's children (this.props.children) inside the &lt;em&gt;SnackBarContext.Provider&lt;/em&gt; to provide necessary values (State's Data and Handlers) to be passed on to &lt;em&gt;SnackBarContext.Consumer&lt;/em&gt; used by our SnackBar component some where down the component tree of it's children. (!important)&lt;/p&gt;

&lt;p&gt;Inside the &lt;em&gt;SnackBarProvider&lt;/em&gt; we assign &lt;code&gt;DEFAULT_STATE&lt;/code&gt; to this.state. &lt;code&gt;DEFAULT_STATE&lt;/code&gt; has the default values to be passed down to the Consumer.&lt;/p&gt;

&lt;p&gt;We need our SnackBar to be stateful for showing and hiding. State's show property will be a boolean used for showing or hiding our SnackBar. Functions handleClose and handleOpen are used as handlers for state changes to do the same in the will be used in our SnackBar.&lt;/p&gt;

&lt;p&gt;handleOpen will accepts an argument displayText the text to displayed in our SnackBar and sets displayText and show to true. And, handleClose will change the show to false and displayText to it's default state i.e, empty string.&lt;/p&gt;

&lt;p&gt;Inside render we'll our &lt;em&gt;SnackBarContext.Provider&lt;/em&gt; to which will pass in prop named value our SnackBarProvider's state (…this.state) and our handlers (handleOpen and handleClose). &lt;em&gt;SnackBarContext.Provider&lt;/em&gt; will enclose our SnackBarProvider's children so we can use &lt;em&gt;SnackBarContext.Consumer&lt;/em&gt; access these values and functions down the our children's component tree.&lt;/p&gt;

&lt;p&gt;Now that we're done with our Provider let's see how to use our Consumer.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Consumer&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;Consumer&amp;gt;
  {value =&amp;gt; /* render something based on the context value */}
&amp;lt;/Consumer&amp;gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Consumer takes a function as a child. The value parameter of the function is the one that contains our prop value passed to our closestProvider.The function receives the current context value and returns a React node. Let's see how we'll use it in our case.&lt;/p&gt;

&lt;p&gt;We'll have a &lt;em&gt;SnackBar&lt;/em&gt; component which will use the props from our Provider to control it's visibility (show/hide functionality).&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const SnackBar = ({ show, handleClose, displayText }) =&amp;gt; (
  &amp;lt;div className="snackBarHolder"&amp;gt;
    {show &amp;amp;&amp;amp; ( // controls visibility
      &amp;lt;div className="snackBar"&amp;gt;
        &amp;lt;span&amp;gt;
          {
            displayText // text to be displayed
          }
        &amp;lt;/span&amp;gt;
        &amp;lt;button onClick={() =&amp;gt; handleClose()}&amp;gt;OK&amp;lt;/button&amp;gt;
      &amp;lt;/div&amp;gt;
    )}
  &amp;lt;/div&amp;gt;
)
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;&lt;em&gt;show&lt;/em&gt; will control the visibility, handleClose will be used by the button in our SnackBar to force the SnackBar to hide and displayText is the main text that will be displayed in our SnackBar.&lt;/p&gt;

&lt;p&gt;So we know that our SnackBar component requires props show, handleClose, displayText for it to work as required. Let's see how to use SnackBarContext.Consumer to get the required props.&lt;/p&gt;

&lt;p&gt;So we'll create a &lt;em&gt;Higher Order Component&lt;/em&gt; that will take a Component as a parameter and passes the value from Provider as props to that Component. Let's call it &lt;em&gt;withSnackBarConsumer&lt;/em&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;/* file: SnackBarContext.jsx */

export const withSnackBarConsumer = WrappedComponent =&amp;gt; {
  const WrapSnackBarConsumer = props =&amp;gt; (
    &amp;lt;SnackBarContext.Consumer&amp;gt;
      {({ show, displayText, handleOpen, handleClose }) =&amp;gt; {
        const snackBarProps = {
          show,
          displayText,
          handleOpen,
          handleClose,
        }
        return &amp;lt;WrappedComponent {...snackBarProps} {...props} /&amp;gt;
      }}
    &amp;lt;/SnackBarContext.Consumer&amp;gt;
  )
  return WrapSnackBarConsumer
}
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Here, &lt;em&gt;withSnackBarConsumer&lt;/em&gt; will accept a WrappedComponent as a parameter and returns WrapSnackBarConsumer which wraps the WrappedComponent with SnackBarContext.Consumer by using our function as a child signature of Consumer.&lt;/p&gt;

&lt;p&gt;Using the Consumer we get the values (show, displayText, handleOpen, handleClose) provided by our Provider and pass these values (snackBarProps) to our WrappedComponent as props. We can use our withSnackBarConsumer to wrap our SnackBar like:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;*/* file: SnackBar.jsx */*

import { withSnackBarConsumer } from './SnackBarContext';

const SnackBar = ({ show, handleClose, displayText }) =&amp;gt; (
  &amp;lt;div className="snackBarHolder"&amp;gt;
   {
    show // controls visibility
    &amp;amp;&amp;amp; (
      &amp;lt;div className="snackBar" &amp;gt;
       &amp;lt;span&amp;gt;{
         displayText // text to be displayed
        }&amp;lt;/span&amp;gt;
       &amp;lt;button onClick={() =&amp;gt; handleClose()}&amp;gt;
          OK
        &amp;lt;/button&amp;gt;
      &amp;lt;/div&amp;gt;
     )
   }
  &amp;lt;/div&amp;gt;
);

export default withSnackBarConsumer(SnackBar);
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Now that we have &lt;em&gt;connected&lt;/em&gt; (Just like Redux, eh ?) our SnackBar to values provided by our SnackBarProvider.&lt;/p&gt;

&lt;p&gt;We can start on how to use the same withSnackBarConsumer to provide other components in our app ability to make our SnackBar visible using handleChange.&lt;/p&gt;

&lt;p&gt;Let's create a SnackBarControl a button with handleOpen using &lt;em&gt;withSnackBarConsumer&lt;/em&gt; HOC.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;/* file: SnackBarControl.jsx */

import { withSnackBarConsumer } from "./SnackBarContext";

const SnackBarControl = ({ text, handleOpen }) =&amp;gt; (
  &amp;lt;button onClick={() =&amp;gt; handleOpen(text, buttonText)}&amp;gt;Show me!&amp;lt;/button&amp;gt;
);

export default withSnackBarConsumer(SnackBarControl);
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;SnackBarControl uses our handleOpen from our SnackBarProvider. We connected SnackBarControl to handleOpen using the our withSnackBarConsumer.&lt;/p&gt;

&lt;p&gt;Now that We have SnackBarControl, SnackBar, SnackBarProvider let's see it in action.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;/* file: App.js from create-react-app */

import React, { Component } from 'react';
import { SnackBarProvider } from './SnackBarContext';
import SnackBarControl from './SnackBarControl.jsx';
import logo from './logo.svg';
import './App.css';

class App extends Component {
  render() {
    return (
      &amp;lt;SnackBarProvider&amp;gt;
         &amp;lt;div className="App"&amp;gt;
            &amp;lt;header className="App-header"&amp;gt;
             &amp;lt;img src={logo} className="App-logo" alt="logo" /&amp;gt;
             &amp;lt;h1 className="App-title"&amp;gt;Welcome to React&amp;lt;/h1
             &amp;lt;/header&amp;gt;
             &amp;lt;SnackBarButton text="Hey There!"/&amp;gt;
          &amp;lt;/div&amp;gt;
        &amp;lt;SnackBar /&amp;gt;
     &amp;lt;/SnackBarProvider&amp;gt;
     );
   }
}

export default App;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Add these styles for your SnackBar inside App.css to make it look like a real snackBar!&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;/* file: App.css from create-react-app */

.SnackBarHolder {
  position: fixed;
  z-index: 50;
  bottom: 20px;
  left: 50%;
  -webkit-animation: fadein 0.5s, fadeout 0.5s 2.5s;
  -moz-animation: fadein 0.5s, fadeout 0.5s 2.5s;
  -ms-animation: fadein 0.5s, fadeout 0.5s 2.5s;
  -o-animation: fadein 0.5s, fadeout 0.5s 2.5s;
  animation: fadein 0.5s, fadeout 0.5s 2.5s;
}
@-webkit-keyframes fadein {
  from {
    bottom: 0;
    opacity: 0;
  }
  to {
    bottom: 20px;
    opacity: 1;
  }
}
@keyframes fadein {
  from {
    bottom: 0;
    opacity: 0;
  }
  to {
    bottom: 20px;
    opacity: 1;
  }
}
@-webkit-keyframes fadeout {
  from {
    bottom: 20px;
    opacity: 1;
  }
  to {
    bottom: 0;
    opacity: 0;
  }
}
@keyframes fadeout {
  from {
    bottom: 20px;
    opacity: 1;
  }
  to {
    bottom: 0;
    opacity: 0;
  }
}
.SnackBar {
  width: 250px;
  padding: 10px;
  background: black;
  display: flex;
  align-items: center;
  justify-content: space-between;
  box-shadow: 0 4px 8px 0 rgba(0, 0, 0, 0.2), 0 6px 20px 0 rgba(0, 0, 0, 0.19);
}
.SnackBar &amp;gt; span {
  color: white;
}
.SnackBar &amp;gt; button {
  background: transparent;
  color: #00b4d2;
  outline: none;
  border: 0;
  cursor: pointer;
}
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Click on &lt;em&gt;Show me!&lt;/em&gt; to see the magic ✨.&lt;/p&gt;

&lt;p&gt;Congrats, You've successfully implemented a simple snack bar using React's Context API.&lt;/p&gt;

&lt;p&gt;Please do read the &lt;a href="https://reactjs.org/docs/context.html"&gt;official docs&lt;/a&gt; for better understanding.&lt;/p&gt;

</description>
      <category>react</category>
      <category>javascript</category>
    </item>
    <item>
      <title>JavaScript, The Beast Within</title>
      <dc:creator>Akshay Ram Vignesh</dc:creator>
      <pubDate>Mon, 27 Aug 2018 23:46:37 +0000</pubDate>
      <link>https://forem.com/akshay5995/javascript-the-beast-within-5667</link>
      <guid>https://forem.com/akshay5995/javascript-the-beast-within-5667</guid>
      <description>&lt;p&gt;I was amused by JavaScript ever since I saw the things that can be done using it and the ease, with what we can achieve such things. I've been working with React JS and Node JS for almost a year and a half now. Needless to say, I'm a big React fanboy.&lt;/p&gt;

&lt;p&gt;Recently, I've started to understand what's really going on under the hood and behind all those layers of abstraction presented to us as developers. This revelation has made go back to basics and understand workings of JavaScript in detail 😲&lt;/p&gt;

&lt;p&gt;Every time I look back at all the work I've achieved with JS without knowing really anything about its inner workings is really amusing to me. Please, take that as an ode to the JavaScript community. You guys are amazing 🙌&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Note: In this article, I hope to cover introduction to JS and 4 topics/ features that intrigued me about JavaScript and made me an avid reader of &lt;a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript"&gt;MDN Web Docs&lt;/a&gt; and other JS related articles. It'll be useful for folks just getting started with JS or, it'll act as a refresher for the experienced.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;I hope you too get inspired to understand this mysterious world of JavaScript 🌎 (or, just learn something new 😉).&lt;/p&gt;

&lt;p&gt;Here’s a little introduction to JS from my personal &lt;a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/A_re-introduction_to_JavaScript"&gt;favourite&lt;/a&gt;.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;JavaScript is notorious for being the &lt;a href="http://crockford.com/javascript/javascript.html"&gt;world’s most misunderstood programming language&lt;/a&gt;.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;It is often derided as being a toy, but beneath its layer of deceptive simplicity, powerful language features await.( Async pun, eh ? 😜 )&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;JavaScript is now used by an incredible number of high-profile applications, showing that deeper knowledge of this technology is an important skill for any web or mobile developer.&lt;/p&gt;

&lt;p&gt;Unlike most programming languages, the JavaScript language has no concept of input or output. It is designed to run as a scripting language in a host environment, and it is up to the host environment to provide mechanisms for communicating with the outside world.&lt;/p&gt;

&lt;p&gt;Host environment is usually a &lt;em&gt;browser&lt;/em&gt;.&lt;/p&gt;

&lt;p&gt;JavaScript interpreters can also be found in a huge list of other places, including Adobe Photoshop, SVG images, server-side environments such as Node.js, NoSQL databases like the open source Apache CouchDB, embedded computers, complete desktop environments like GNOME (one of the most popular GUIs for GNU/Linux operating systems), etc.&lt;/p&gt;

&lt;p&gt;JavaScript is a multi-paradigm, dynamic language with types and operators, standard built-in objects, and methods. Its syntax is based on the Java and C languages — many structures from those languages apply to JavaScript as well.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;I’ll also point you to some articles, if you wish to read more. These can be features of ES6 or it’s predecessors.&lt;/p&gt;
&lt;/blockquote&gt;




&lt;h2&gt;
  
  
  What’s with the name ?
&lt;/h2&gt;

&lt;p&gt;&lt;em&gt;or, What's ECMAScript ?&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;JavaScript was created in 1995 by Brendan Eich (Netscape Engineer). It was originally named Mocha and was changed to be called LiveScript, but it was renamed after a marketing decision that attempted to capitalise on the popularity of Java language at that point in time.&lt;/p&gt;

&lt;p&gt;Netscape submitted JavaScript to ECMA (a European standards organisation), it resulted in the first edition of the ECMAScript standard that year.&lt;/p&gt;

&lt;p&gt;The standard received a significant update as ECMAScript edition 3 in 1999, and it has stayed pretty much stable ever since.&lt;/p&gt;

&lt;p&gt;The fourth edition was abandoned, due to political differences concerning language complexity. Many parts of the fourth edition formed the basis for ECMAScript edition 5, published in December of 2009, and for the 6th major edition of the standard, published in June of 2015.&lt;/p&gt;

&lt;p&gt;So in conclusion, I believe JavaScript is considered the Language which implements a standard called ECMAScript.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;JavaScript is the implementation of the standard that is, ECMAScript.&lt;/p&gt;
&lt;/blockquote&gt;




&lt;h2&gt;
  
  
  Prototypal Inheritance and Classes
&lt;/h2&gt;

&lt;p&gt;&lt;em&gt;One of the most fascinating features for me personally&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;What's prototypal inheritance you ask ?&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;JavaScript only has one construct: &lt;em&gt;objects&lt;/em&gt;. Each object has a private property which holds a link to another object called its &lt;em&gt;prototype&lt;/em&gt;.&lt;/p&gt;

&lt;p&gt;That prototype object has a prototype of its own, and so on until an object is reached with null as its prototype. By definition, null has no prototype, and acts as the final link in this prototype chain. Nearly all objects in JavaScript are instances of Object which sits on the top of a prototype chain. Every object in JS can have another object as its prototype. Then the former object inherits all of latter's properties.&lt;/p&gt;

&lt;p&gt;An object specifies its prototype via the internal property &lt;code&gt;[[Prototype]]&lt;/code&gt;. The chain of objects connected by the &lt;code&gt;[[Prototype]]&lt;/code&gt; property is called the prototype chain&lt;/p&gt;

&lt;p&gt;The &lt;code&gt;__proto__&lt;/code&gt; property exposes the internal prototype linkage.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--sVTA1RsH--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/800/0%2Asacpzj7gNySk-x8O.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--sVTA1RsH--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/800/0%2Asacpzj7gNySk-x8O.png" alt="prototypal inheritance example"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;prototype&lt;/em&gt; vs &lt;code&gt;__proto__&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;The &lt;em&gt;prototype&lt;/em&gt; is a property on a constructor function that sets what will become the &lt;code&gt;__proto__&lt;/code&gt; property on the constructed object.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;var animal = {
  eats: true,
  walk() {
    console.log("walking!!")
  },
}

var rabbit = {
  jumps: true,
  __proto__ : animal,
}

var bugsBunny = {
  likesEating: "Cartoon Carrots",
  isCartoon: true,
  __proto__ : rabbit,
}

bugsBunny.walk() // walking!!!
// resolved by going up the prototype chain to 'animal'

console.log(bugsBunny.jumps) // true
// resolved by going up the prototype chain to 'rabbit'
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Now, tell me about classes ?&lt;/p&gt;

&lt;p&gt;Okay, Now classes in JavaScript are just syntactic sugar on top of it's prototypal inheritance.( Making prototypal inheritance more classy for all OOPs people out there 😅)&lt;/p&gt;

&lt;p&gt;ES6 introduced a new set of keywords implementing classes. i.e, class, constructor, static, extends, and super&lt;/p&gt;

&lt;p&gt;I'm gonna let you take it from here to find out more about classes.&lt;/p&gt;

&lt;p&gt;_Sources: &lt;a href="https://medium.com/r/?url=https%3A%2F%2Fdeveloper.mozilla.org%2Fen-US%2Fdocs%2FWeb%2FJavaScript%2FReference%2FClasses"&gt;Classes&lt;/a&gt;&lt;/p&gt;




&lt;h2&gt;
  
  
  What is "this " ?
&lt;/h2&gt;

&lt;p&gt;&lt;em&gt;Spoiler: it's just spell binding&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;code&gt;this&lt;/code&gt; behaves a little differently in JavaScript compared to other languages. It also has some differences between strict and non-strict mode in Javascript.&lt;/p&gt;

&lt;p&gt;The value of &lt;code&gt;this&lt;/code&gt; is determined by how a function is called.It can't be set by assignment during execution, and it may be different each time the function is called.&lt;/p&gt;

&lt;h3&gt;
  
  
  Global Context
&lt;/h3&gt;

&lt;p&gt;In non-strict mode by default this points to the global window object in browser, and in strict mode by default &lt;em&gt;this&lt;/em&gt; is &lt;em&gt;undefined&lt;/em&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;In browser
console.log(this === window); //true

In Node
console.log(this === global); //true

'use strict'
console.log(this); //undefined
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;h3&gt;
  
  
  Function Context
&lt;/h3&gt;

&lt;p&gt;The value of &lt;code&gt;this&lt;/code&gt; remains at whatever it was set to when entering the execution context.&lt;/p&gt;

&lt;p&gt;To pass the value of &lt;code&gt;this&lt;/code&gt; from one context to another, use call, or apply:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;var obj1 = { a: "Custom" }

var a = "Global"

function whatIsA() {
  return this.a
}

console.log(whatIsA()) //Global

console.log(whatIsA().call(obj1)) //Custom
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;h3&gt;
  
  
  Bind()
&lt;/h3&gt;

&lt;p&gt;ES5 introduced a new function for Function.prototype called the bind().&lt;/p&gt;

&lt;p&gt;Calling func.bind(someObject)creates a new function with the same body and scope as func, but where this occurs in the original function, in the new function it is permanently bound to the first argument of bind&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// function WhatIsA from the above example
var obj2 = { a: 'I'm Object 2's a!' };

var whatIsAInObj2 = whatIsA.bind(obj2);

console.log(whatIsAInObj2()); // I'm Object 2's a!
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;h3&gt;
  
  
  Arrow Functions
&lt;/h3&gt;

&lt;p&gt;With the introduction of arrow functions &lt;code&gt;this&lt;/code&gt; retains the value of the enclosing lexical context's &lt;code&gt;this&lt;/code&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;var obj = {
  bar: function() {
    var x = () =&amp;gt; this
    return x
  },
}

var fn = obj.bar()

console.log(fn() === obj) // true
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;I can keep going.But, for more on this take a look at the &lt;a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/this"&gt;MDN Docs&lt;/a&gt;. 😉&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Note: Read about how this binding is only affected by the most immediate member reference.&lt;/em&gt;&lt;/p&gt;




&lt;h2&gt;
  
  
  Hoisting ⬆️
&lt;/h2&gt;

&lt;p&gt;&lt;em&gt;Up and up and up ? ( Coldplay fans will get it 🎶)&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Hoisting came in to picture or specification only with ES6.&lt;/p&gt;

&lt;p&gt;Hoisting was thought up as a general way of thinking about how execution contexts (specifically the creation and execution phases) work in JavaScript.&lt;/p&gt;

&lt;p&gt;A definition of hoisting might suggest that variable and function declarations are physically moved to the top of your code.&lt;/p&gt;

&lt;p&gt;It's not true , the variable and function declarations are put into memory during the compile phase, but stay exactly where you typed them in your code.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;console.log(sayHello("world!")) // Hello world!

console.log(a)

// undefined and not 'ReferenceError' due to hoisting
console.log(sayOla("world!"))

// TypeError: sayOla is not a function
function sayHello(param) {
  return "Hello " + param
}

var a = 1
var sayOla = function(param) {
  return "Hello " + param
}
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Above example shows hoisting in action. Conceptually, how your run time sees it is.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function sayHello(param) {
  return "Hello " + param
}

var a
var sayOla

console.log(sayHello("world!")) // Hello world!
console.log(a)
// undefined and not 'ReferenceError' due to hoisting
console.log(sayOla("world!"))
// TypeError: sayOla is not a function
a = 1
sayOla = function(param) {
  return "Hello " + param
}
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;&lt;em&gt;Note: only declarations are hoisted but not assignments. also, class declarations are not hoisted.&lt;/em&gt;&lt;/p&gt;




&lt;h2&gt;
  
  
  Now, Let's bring it to a "Closure" 🔚
&lt;/h2&gt;

&lt;p&gt;&lt;em&gt;Another JS pun (sorry!)&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;A &lt;em&gt;closure&lt;/em&gt; is the function bundled together (enclosed) with references to its surrounding state (the &lt;em&gt;lexical environment&lt;/em&gt;).&lt;/p&gt;

&lt;p&gt;Closure gives you access to an outer function's scope from an inner function. In JavaScript, closures are created every time a function is created, at function creation time.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function outerFunction() {
  var x = "Hello "
  return function(param) {
    return x + param
  }
}

var newFunc = outerFunction()

console.log(newFunc("World!")) // Hello World!
// Even after returning the function has access to variable x
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Closures are usually used to give objects data privacy and to fix order of partial application of functions.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// partial application

function makeAdder(x) {
  return function(y) {
    return x + y
  }
}

var add5 = makeAdder(5)

console.log(add5(10)) // 15
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;






&lt;p&gt;I hope this article got you inspired or curious to learn more about JavaScript.&lt;/p&gt;

&lt;p&gt;PS: I'll just leave you with my personal favourite JS articles/ docs 💌&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/A_re-introduction_to_JavaScript"&gt;A re-Introduction to JavaScript&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/EventLoop"&gt;Event Loop&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://medium.com/javascript-scene/curry-or-partial-application-8150044c78b8"&gt;Curry or Partial Application&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://codeburst.io/all-about-javascript-functions-in-1-article-49bfd94b31ab"&gt;All About JavaScript functions&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://medium.com/javascript-scene/master-the-javascript-interview-what-is-functional-programming-7f218c68b3a0"&gt;Functional Programming in JS&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://medium.com/javascript-scene/master-the-javascript-interview-what-s-the-difference-between-class-prototypal-inheritance-e4cd0a7562e9"&gt;Class and Prototypal Inheritance&lt;/a&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;You can also follow this really interesting &lt;a href="https://www.youtube.com/channel/UCO1cgjhGzsSYb1rsB4bFe4Q"&gt;YouTube channel&lt;/a&gt; for cool JS related stuff and more .&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>beginners</category>
    </item>
    <item>
      <title>How To Embed Microsoft Power BI Charts Into Your React Application</title>
      <dc:creator>Akshay Ram Vignesh</dc:creator>
      <pubDate>Sun, 12 Aug 2018 23:46:37 +0000</pubDate>
      <link>https://forem.com/akshay5995/how-to-embed-microsoft-power-bi-charts-into-your-react-application-897</link>
      <guid>https://forem.com/akshay5995/how-to-embed-microsoft-power-bi-charts-into-your-react-application-897</guid>
      <description>&lt;p&gt;Embedding Microsoft Power BI charts into your React Application can be breeze with the right tools.&lt;/p&gt;

&lt;p&gt;Note: &lt;em&gt;This article assumes you have a fairly decent idea about Microsoft Power BI and few related terminologies.&lt;/em&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  TL;DR
&lt;/h2&gt;

&lt;p&gt;Install &lt;code&gt;powerbi-report-component&lt;/code&gt; using your favourite package manager.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;npm i powerbi-report-component --save-dev&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;or,&lt;/p&gt;

&lt;p&gt;&lt;code&gt;yarn add powerbi-report-component --dev&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Basic usage,&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import Report from "powerbi-report-component";

&amp;lt;Report
  embedType="report"
  tokenType="Embed"
  accessToken=""
  embedUrl=""
  embedId=""
  permissions="All"
  style={myStyleObject}
/&amp;gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;






&lt;h2&gt;
  
  
  Now, for the those who stayed :)
&lt;/h2&gt;

&lt;p&gt;Embedding a Power BI report into your React Application can be a pain for a beginner. Even though the Microsoft's documentation on the topic is pretty neat.&lt;/p&gt;

&lt;p&gt;I'm just gonna tell you what's need from a React developer's perspective and not go into the details of implementation or architecture.&lt;/p&gt;

&lt;p&gt;There are two approaches that you can take to embed your Power BI Report:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;User Owns Data&lt;/li&gt;
&lt;li&gt;App Owns Data&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;The main difference is:&lt;/p&gt;

&lt;p&gt;User Owns Data sample is for Embedding for your organisation, the embedded reports readers can be Power BI Pro or free users in your organisation. Users have to log-in with their PBI account. Power BI Premium license is required. (i.e, Users who are part of your AD)&lt;/p&gt;

&lt;p&gt;App Owns Data sample is for Embedding for your customers, the embedded report readers can be your own customers(say you're an ISV application provider). So no log-in. Power BI Embedded license is required.(i.e, Users outside your AD)&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Source: &lt;a href="https://community.powerbi.com/t5/Developer/App-vs-User-Owns-Data/td-p/300729"&gt;https://community.powerbi.com/t5/Developer/App-vs-User-Owns-Data/td-p/300729&lt;/a&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;You have to choose who will be using your application that's gonna contain your embedded report i.e, Internal users(AD User) vs. External users(Non AD).&lt;/p&gt;

&lt;p&gt;Now that you've decided on which approach you're gonna choose.&lt;/p&gt;

&lt;p&gt;Hopefully, You have your report ready and are able to view it in &lt;a href="https://powerbi.microsoft.com"&gt;https://powerbi.microsoft.com&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Now, navigate to your report under your workspaces your URL should look something like this:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;a href="https://app.powerbi.com/groups/%7Bworkspace-id%7D/reports/%7Breport-id%7D"&gt;https://app.powerbi.com/groups/{workspace-id}/reports/{report-id}&lt;/a&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;for dashboards you might have something like this:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;a href="https://app.powerbi.com/groups/%7Bworkspace-id%7D/dashboards/%7Bdashboard-id%7D"&gt;https://app.powerbi.com/groups/{workspace-id}/dashboards/{dashboard-id}&lt;/a&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;To Embed your report you'll need the following:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Report ID: from the URL&lt;/li&gt;
&lt;li&gt;Workspace ID: also, from the URL&lt;/li&gt;
&lt;li&gt;Token: AAD or Embed Token (For authetication))&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;Note: AAD token is used while taking the User Owns Data Approach and Embed token is used when taking App Owns Data Approach.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Embed Url:&lt;/em&gt; (Will consist of Report ID and Workspace ID)&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;a href="https://app.powerbi.com/reportEmbed?reportId=_report-id_&amp;amp;groupId=_workspace-id_"&gt;https://app.powerbi.com/reportEmbed?reportId=&lt;em&gt;report-id&lt;/em&gt;&amp;amp;groupId=&lt;em&gt;workspace-id&lt;/em&gt;&lt;/a&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;There are mainly two ways you can proceed with embedding the report into your react application.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Using an iframe&lt;/li&gt;
&lt;li&gt;Using Power BI JS API provided by Microsoft&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Using an iframe is pretty straightforward but, this doesn't provide the flexibility that a React component would provide, like callbacks or event triggers.&lt;/p&gt;

&lt;p&gt;You can use the generated URL to embed using iframe like this,&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;iframe
  width="800"
  height="600"
  src="http://myserver/reports/powerbi/Sales?rs:embed=true"
  allowfullscreen="true"
&amp;gt;
&amp;lt;/iframe&amp;gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;But, naturally as JS developers we tend to go with the more flexible JS API.&lt;/p&gt;

&lt;p&gt;You can take a look at Microsoft's &lt;a href="https://microsoft.github.io/PowerBI-JavaScript/demo/v2-demo/index.html#"&gt;demo page&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;They have a very clear explanation and demo in Vanilla JS which uses their Javascript API.&lt;/p&gt;

&lt;p&gt;You might be wondering, the demo is in Vanilla JS so if I have to make it a React Component and use it in my app.hmm, that might take a while 🤔&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;powerbi-report-component to the rescue! ✨&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Check out the &lt;a href="https://www.npmjs.com/package/powerbi-report-component"&gt;package&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Usage,&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import Report from "powerbi-report-component";

&amp;lt;Report
  embedType="report" // or "dashboard"
  tokenType="Embed" // or "Aad"
  accessToken="" // accessToken goes here
  embedUrl="" // embedUrl goes here
  embedId="" // Report or Dashboard ID goes here
  permissions="All" // or "View"
  style={myStyleObject}
/&amp;gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Currently supported features:&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Custom styling by passing style to your embedded report component.&lt;/li&gt;
&lt;li&gt;The component also lets you pass callbacks to trigger on events like:&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;em&gt;Page Change&lt;/em&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;onPageChange={(data) =&amp;gt;
  console.log(`Page name :{data.newPage.displayName}`)
}
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;&lt;em&gt;Load&lt;/em&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;onLoad={(report) =&amp;gt; {
      console.log('Report Loaded!');
      this.report = report;
// Read docs to know how to use the report object that is returned
    }
}
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;&lt;em&gt;Data Element Clicked&lt;/em&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;onSelectData={(data) =&amp;gt;
  console.log(`You clicked on chart: {data.visual.title}`)
}
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;Use 'report' object returned to parent component for:&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Fullscreen&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;setFullscreen = () =&amp;gt; this.report.fullscreen()
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Print Report&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;printReport = () =&amp;gt; this.report.print()
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Change report mode, show/hide visual headers, filters(set, get, remove)&lt;/p&gt;

&lt;p&gt;Change Mode&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// mode can be "view" or "edit"

changeMode = mode =&amp;gt; this.report.switchMode(mode)
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Show or Hide Visual Headers&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;toggleAllVisualHeaders = bool =&amp;gt; {
  const newSettings = {
    visualSettings: {
      visualHeaders: [
        {
          settings: {
            visible: bool,
          },
        },
      ],
    },
  }
  this.report
    .updateSettings(newSettings)
    .then(function() {
      console.log(`Visual header was toggled to {bool}`)
    })
    .catch(function(errors) {
      console.log(errors)
    })
}
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Set Filters&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;//example filter object from Microsoft's demo page

    const filter = {
      $schema: "http://powerbi.com/product/schema#basic",
      target: {
        table: "Store",
        column: "Chain"
      },
      operator: "In",
      values: ["Lindseys"]
    };

    // using event handlers

    setFilter = (filter) =&amp;gt;
    this.report.setFilters([filter]).catch(function (errors) {
        console.log(errors);
    });

    // during load of report

    onLoad = (report) =&amp;gt; {
      report.setFilters([filter]).catch(function (errors) {
        console.log(errors);
      });
      this.report = report;
    }
  }
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Get Filters&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;getFilter = () =&amp;gt;
  this.report
    .getFilters()
    .then(function(filters) {
      console.log(filters)
    })
    .catch(function(errors) {
      console.log(errors)
    })
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Remove Filters&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;removeFilters = () =&amp;gt;
  this.report.removeFilters().catch(function(errors) {
    console.log(errors)
  })
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;More features coming soon! ⚡️&lt;/p&gt;

&lt;p&gt;Links: &lt;a href="http://akshay5995.github.io/powerbi-report-component"&gt;Demo site&lt;/a&gt;, &lt;a href="https://github.com/akshay5995/powerbi-report-component"&gt;GitHub&lt;/a&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;I would love to hear your thoughts and feedback (also any request for new features at &lt;a href="https://github.com/akshay5995/powerbi-report-component/issues"&gt;https://github.com/akshay5995/powerbi-report-component/issues&lt;/a&gt;).&lt;/p&gt;
&lt;/blockquote&gt;

</description>
      <category>react</category>
      <category>powerbi</category>
      <category>microsoft</category>
    </item>
  </channel>
</rss>
