-
Includes:
- Place to put code
- Place to keep track of project dependencies
- Development webserver
-
Meteor -> keep track of data in our app
-
React -> Take data to product HTML, handle user events
Project Images Gallery
Meteor.startup(() => {}): takes the function, run it when Meteor has started up: meteor has loaded, all HTML & DOM elements are rendered
Project Employee Directory
-
Folder:
- client: to be bundled and served to client
- server: server code
- imports: shared between both client & server, executed first, before any client or server code
-
Generate fake data using
Faker -
Subscribe/Publish system
meteor remove autopublishto restrict access to backend data
-
react-meteor-datacan be used to create a container - a function that update some amount of data being passed to the component whenever a subscription changes -> watch collection, if update, load all new updated records to the react component -
Update & re-render component without using component-level state
Project URL Shortener
- Way to store links
- Redirect user from a shortened URL to the original one
- Record a number of clicks for each URL
- Add Bootstrap as a Meteor package:
meteor add twbs:bootstrap@3.3.6 npm install --save react react-dom- Setup
Headercomponent - Create
Linkscollection inimports/collectionto be shared between both client and server - Create URL form component, on form submit:
- Validate URL input from user ->
this.refs.inputRef.value - Create new token that matches this URL
- Add the token and original URL to a
linkscollection
- Validate URL input from user ->
meteor remove autopublishfor setup secure publish/subscribe system
meteor remove insecure-> to securely access database & save dataMeteor.methods({'method_name': method_function})andMeteor.call('method_name', args[, callback])for creating and calling secure methods between client and server- Validate user url input
- Using
valid-urlnpm package and it'sisUri(url)function - Using
check,Matchfrommeteor/checkpackagecheck: run validation on a var, if a var passes ->checkdoes nothing, else -> throw an errorMatch: used to run customed validation function
- Using
- Setup publish/subscribe system
meteor add react-meteor-data
- Use
meteor/webapp- Meteor server, for handling incoming request
WebApp.connectHandlers.use(req => {/* handle request here */})
or
WebApp.connectHandlers.use(middleware) - Install
connect-routefor routing (similar to Express routing) -> creates a middleware that takes in HTTP request, check route then does according actions - Update number of clicks using Mongo Modifier
{$inc: {}}inside theupdate()method, eg.Links.update(link, { $inc: { clicks: 1 }})
Project dir Markdown Bin
- User can navigate between different pages ->
react-router - Need a full authentication system, using builtin Meteor methods
binscollection belongs specifically to only the owner/editor of a bin- //TODO
- Explore more on user management
- Let users choose to display bins that they own or they are shared with
meteor add react-meteor-datameteor add twbs:bootstrap@3.3.6meteor remove insecuremeteor remove autopublishnpm install react react-dom react-addons-pure-render-mixin
All already written by Meteor
- Get Blaze (or generally other rendering libraries) to work with React to make use of Blaze account authentication forms
- Let React renders a DOM element
- Use React life cycle methods for calling function automatically
- Find that particular DOM node and use another library to render to it (eg. inside
componentDidMount()) - Need to manually clean up that part rendered by other libraries (eg. using
componentWillUnmount())
- Install dependencies for this:
meteor add accounts-ui accounts-password - Try using native implementation of
bcrypt:meteor npm install --save bcrypt(faster than JS-implementation used by default in Meteor)
- Schema: createdAt, content, ownerId, sharedWith
- Access current user by using
this.userIdinside of the Meteor methods - Use of
functionkeyword vs()=>{}:thisinside an arrow function is the surrounding context- Use
functionkeyword,thiscan be referred to the runtime context, so we can usethis.userId
- Setup publish/subscribe system for providing bins from the server and displaying bins on the client
- Use
createContainer()frommeteor/react-meteor-datato subscribe thebinscollection to theBinsListReact component
- Use
- Handle bin element
onClick-> use arrow function (only function definition without invoking)onClick={() => this.onBinRemove(bin)}instead of passing athis.onBinRemove(bin)function (this is invoked with probably incorrectbinargument) right in the JSX -> can pass the correctbinargument into that function
- Use of
BrowserRoute,Route,Switch - Access url params from React component using
props.match.params.paramName - Alternative for anchor tag:
Linkfromreact-router-dom - Use
this.props.history.push("url_str")to redirect the user
- Using React Codemirror
- Note on react-codemirror bug -> editor doesn't re-render the component when state changes
- Use
"@skidding/react-codemirror": "^1.0.0"for npm package instead of the original one - Using
import CodeMirror from '@skidding/react-codemirror';
- Use
- Install dependencies:
npm install --save react-codemirrormeteor add sgslo:cmstylefor styling the editor
- Use
onEditorChange(content)to update and store bin content when user changes markdownnpm package for translate markdown str into html view- Use
dangerouslySetInnerHTML={{ __html: rawHtml }}in a component to render html string as HTML. Unsafe because of higher chance for XSS to break the website
- Create component for handle shared email
- Setup new publication -> publish all the bins that an user has been shared with
Meteor.users.find(...)accessesusersMongo collection, auto-created by Meteor to stored registered users- Subcribe to the new
sharedBinspublication for components: BinsMain and BinsList