\begin{quote}
Map {\ttfamily visit} over an array of objects. \end{quote}
\hypertarget{md_sfcode_node_modules_map_visit_README_autotoc_md16985}{}\doxysection{Install}\label{md_sfcode_node_modules_map_visit_README_autotoc_md16985}
Install with \href{https://www.npmjs.com/}{\texttt{ npm}}\+:


\begin{DoxyCode}{0}
\DoxyCodeLine{\$ npm install -\/-\/save map-\/visit }

\end{DoxyCode}
\hypertarget{md_sfcode_node_modules_map_visit_README_autotoc_md16986}{}\doxysection{Usage}\label{md_sfcode_node_modules_map_visit_README_autotoc_md16986}

\begin{DoxyCode}{0}
\DoxyCodeLine{var mapVisit = require('map-\/visit'); }

\end{DoxyCode}
\hypertarget{md_sfcode_node_modules_map_visit_README_autotoc_md16987}{}\doxysection{What does this do?}\label{md_sfcode_node_modules_map_visit_README_autotoc_md16987}
{\bfseries{Assign/\+Merge/\+Extend vs. Visit}}

Let\textquotesingle{}s say you want to add a {\ttfamily set} method to your application that will\+:


\begin{DoxyItemize}
\item set key-\/value pairs on a {\ttfamily data} object
\item extend objects onto the {\ttfamily data} object
\item extend arrays of objects onto the data object
\end{DoxyItemize}

{\bfseries{Example using {\ttfamily extend}}}

Here is one way to accomplish this using Lo-\/\+Dash\textquotesingle{}s {\ttfamily extend} (comparable to {\ttfamily Object.\+assign})\+:


\begin{DoxyCode}{0}
\DoxyCodeLine{var \_ = require('lodash');}
\DoxyCodeLine{}
\DoxyCodeLine{var obj = \{}
\DoxyCodeLine{  data: \{\},}
\DoxyCodeLine{  set: function (key, value) \{}
\DoxyCodeLine{    if (Array.isArray(key)) \{}
\DoxyCodeLine{      \_.extend.apply(\_, [obj.data].concat(key));}
\DoxyCodeLine{    \} else if (typeof key === 'object') \{}
\DoxyCodeLine{      \_.extend(obj.data, key);}
\DoxyCodeLine{    \} else \{}
\DoxyCodeLine{      obj.data[key] = value;}
\DoxyCodeLine{    \}}
\DoxyCodeLine{  \}}
\DoxyCodeLine{\};}
\DoxyCodeLine{}
\DoxyCodeLine{obj.set('a', 'a');}
\DoxyCodeLine{obj.set([\{b: 'b'\}, \{c: 'c'\}]);}
\DoxyCodeLine{obj.set(\{d: \{e: 'f'\}\});}
\DoxyCodeLine{}
\DoxyCodeLine{console.log(obj.data);}
\DoxyCodeLine{//=> \{a: 'a', b: 'b', c: 'c', d: \{ e: 'f' \}\} }

\end{DoxyCode}


The above approach works fine for most use cases. However, {\bfseries{if you also want to emit an event}} each time a property is added to the {\ttfamily data} object, or you want more control over what happens as the object is extended, a better approach would be to use {\ttfamily visit}.

{\bfseries{Example using {\ttfamily visit}}}

In this approach\+:


\begin{DoxyItemize}
\item when an array is passed to {\ttfamily set}, the {\ttfamily map\+Visit} library calls the {\ttfamily set} method on each object in the array.
\item when an object is passed, {\ttfamily visit} calls {\ttfamily set} on each property in the object.
\end{DoxyItemize}

As a result, the {\ttfamily data} event will be emitted every time a property is added to {\ttfamily data} (events are just an example, you can use this approach to perform any necessary logic every time the method is called).


\begin{DoxyCode}{0}
\DoxyCodeLine{var mapVisit = require('map-\/visit');}
\DoxyCodeLine{var visit = require('object-\/visit');}
\DoxyCodeLine{}
\DoxyCodeLine{var obj = \{}
\DoxyCodeLine{  data: \{\},}
\DoxyCodeLine{  set: function (key, value) \{}
\DoxyCodeLine{    if (Array.isArray(key)) \{}
\DoxyCodeLine{      mapVisit(obj, 'set', key);}
\DoxyCodeLine{    \} else if (typeof key === 'object') \{}
\DoxyCodeLine{      visit(obj, 'set', key);}
\DoxyCodeLine{    \} else \{}
\DoxyCodeLine{      // simulate an event-\/emitter}
\DoxyCodeLine{      console.log('emit', key, value);}
\DoxyCodeLine{      obj.data[key] = value;}
\DoxyCodeLine{    \}}
\DoxyCodeLine{  \}}
\DoxyCodeLine{\};}
\DoxyCodeLine{}
\DoxyCodeLine{obj.set('a', 'a');}
\DoxyCodeLine{obj.set([\{b: 'b'\}, \{c: 'c'\}]);}
\DoxyCodeLine{obj.set(\{d: \{e: 'f'\}\});}
\DoxyCodeLine{obj.set(\{g: 'h', i: 'j', k: 'l'\});}
\DoxyCodeLine{}
\DoxyCodeLine{console.log(obj.data);}
\DoxyCodeLine{//=> \{a: 'a', b: 'b', c: 'c', d: \{ e: 'f' \}, g: 'h', i: 'j', k: 'l'\}}
\DoxyCodeLine{}
\DoxyCodeLine{// events would look something like:}
\DoxyCodeLine{// emit a a}
\DoxyCodeLine{// emit b b}
\DoxyCodeLine{// emit c c}
\DoxyCodeLine{// emit d \{ e: 'f' \}}
\DoxyCodeLine{// emit g h}
\DoxyCodeLine{// emit i j}
\DoxyCodeLine{// emit k l }

\end{DoxyCode}
\hypertarget{md_sfcode_node_modules_map_visit_README_autotoc_md16988}{}\doxysection{About}\label{md_sfcode_node_modules_map_visit_README_autotoc_md16988}
\hypertarget{md_sfcode_node_modules_map_visit_README_autotoc_md16989}{}\doxysubsection{Related projects}\label{md_sfcode_node_modules_map_visit_README_autotoc_md16989}

\begin{DoxyItemize}
\item \href{https://www.npmjs.com/package/collection-visit}{\texttt{ collection-\/visit}}\+: Visit a method over the items in an object, or map visit over the objects… \href{https://github.com/jonschlinkert/collection-visit}{\texttt{ more}} $\vert$ \href{https://github.com/jonschlinkert/collection-visit}{\texttt{ homepage}}
\item \href{https://www.npmjs.com/package/object-visit}{\texttt{ object-\/visit}}\+: Call a specified method on each value in the given object. $\vert$ \href{https://github.com/jonschlinkert/object-visit}{\texttt{ homepage}}
\end{DoxyItemize}\hypertarget{md_sfcode_node_modules_map_visit_README_autotoc_md16990}{}\doxysubsection{Contributing}\label{md_sfcode_node_modules_map_visit_README_autotoc_md16990}
Pull requests and stars are always welcome. For bugs and feature requests, \href{../../issues/new}{\texttt{ please create an issue}}.\hypertarget{md_sfcode_node_modules_map_visit_README_autotoc_md16991}{}\doxysubsection{Contributors}\label{md_sfcode_node_modules_map_visit_README_autotoc_md16991}
\tabulinesep=1mm
\begin{longtabu}spread 0pt [c]{*{2}{|X[-1]}|}
\hline
\PBS\centering \cellcolor{\tableheadbgcolor}\textbf{ {\bfseries{Commits}}   }&\PBS\centering \cellcolor{\tableheadbgcolor}\textbf{ {\bfseries{Contributor}}    }\\\cline{1-2}
\endfirsthead
\hline
\endfoot
\hline
\PBS\centering \cellcolor{\tableheadbgcolor}\textbf{ {\bfseries{Commits}}   }&\PBS\centering \cellcolor{\tableheadbgcolor}\textbf{ {\bfseries{Contributor}}    }\\\cline{1-2}
\endhead
15   &\href{https://github.com/jonschlinkert}{\texttt{ jonschlinkert}}    \\\cline{1-2}
7   &\href{https://github.com/doowb}{\texttt{ doowb}}   \\\cline{1-2}
\end{longtabu}
\hypertarget{md_sfcode_node_modules_map_visit_README_autotoc_md16992}{}\doxysubsection{Building docs}\label{md_sfcode_node_modules_map_visit_README_autotoc_md16992}
\+\_\+(This project\textquotesingle{}s readme.\+md is generated by \href{https://github.com/verbose/verb-generate-readme}{\texttt{ verb}}, please don\textquotesingle{}t edit the readme directly. Any changes to the readme must be made in the .verb.md readme template.)\+\_\+

To generate the readme, run the following command\+:


\begin{DoxyCode}{0}
\DoxyCodeLine{\$ npm install -\/g verbose/verb\#dev verb-\/generate-\/readme \&\& verb }

\end{DoxyCode}
\hypertarget{md_sfcode_node_modules_map_visit_README_autotoc_md16993}{}\doxysubsection{Running tests}\label{md_sfcode_node_modules_map_visit_README_autotoc_md16993}
Running and reviewing unit tests is a great way to get familiarized with a library and its API. You can install dependencies and run tests with the following command\+:


\begin{DoxyCode}{0}
\DoxyCodeLine{\$ npm install \&\& npm test }

\end{DoxyCode}
\hypertarget{md_sfcode_node_modules_map_visit_README_autotoc_md16994}{}\doxysubsection{Author}\label{md_sfcode_node_modules_map_visit_README_autotoc_md16994}
{\bfseries{Jon Schlinkert}}


\begin{DoxyItemize}
\item \href{https://github.com/jonschlinkert}{\texttt{ github/jonschlinkert}}
\item \href{https://twitter.com/jonschlinkert}{\texttt{ twitter/jonschlinkert}}
\end{DoxyItemize}\hypertarget{md_sfcode_node_modules_map_visit_README_autotoc_md16995}{}\doxysubsection{License}\label{md_sfcode_node_modules_map_visit_README_autotoc_md16995}
Copyright © 2017, \href{https://github.com/jonschlinkert}{\texttt{ Jon Schlinkert}}. Released under the \mbox{[}MIT License\mbox{]}(LICENSE).

\DoxyHorRuler{0}


{\itshape This file was generated by \href{https://github.com/verbose/verb-generate-readme}{\texttt{ verb-\/generate-\/readme}}, v0.\+5.\+0, on April 09, 2017.} 