Merge pull request #659 from metamaps/feature/js-fiddling

simplify js
This commit is contained in:
Devin Howard 2016-09-24 23:35:50 +08:00 committed by GitHub
commit 82b7c7e5ac
9 changed files with 31 additions and 51 deletions

View file

@ -186,7 +186,7 @@ const Filter = {
$('#filter_by_' + listToModify + ' li[data-id="' + identifier + '"]').fadeOut('fast', function () { $('#filter_by_' + listToModify + ' li[data-id="' + identifier + '"]').fadeOut('fast', function () {
$(this).remove() $(this).remove()
}) })
index = self.visible[filtersToUse].indexOf(identifier) const index = self.visible[filtersToUse].indexOf(identifier)
self.visible[filtersToUse].splice(index, 1) self.visible[filtersToUse].splice(index, 1)
}) })

View file

@ -1,17 +1,19 @@
/* global $ */
/* /*
* Metamaps.Backbone * Dependencies:
* Metamaps.Backbone
*/ */
const Mapper = { const Mapper = {
// this function is to retrieve a mapper JSON object from the database // this function is to retrieve a mapper JSON object from the database
// @param id = the id of the mapper to retrieve // @param id = the id of the mapper to retrieve
get: function (id, callback) { get: function (id, callback) {
return fetch(`/users/${id}.json`, { $.ajax({
}).then(response => { url: `/users/${id}.json`,
if (!response.ok) throw response success: data => {
return response.json() callback(new Metamaps.Backbone.Mapper(data))
}).then(payload => { }
callback(new Metamaps.Backbone.Mapper(payload))
}) })
} }
} }

View file

@ -1,7 +0,0 @@
import Maps from '../components/Maps'
const ReactComponents = {
Maps
}
export default ReactComponents

View file

@ -4,7 +4,7 @@ import React from 'react'
import ReactDOM from 'react-dom' // TODO ensure this isn't a double import import ReactDOM from 'react-dom' // TODO ensure this isn't a double import
import Active from '../Active' import Active from '../Active'
import ReactComponents from '../ReactComponents' import Maps from '../../components/Maps'
/* /*
* - Metamaps.Loading * - Metamaps.Loading
@ -42,7 +42,7 @@ const ExploreMaps = {
loadMore: self.loadMore loadMore: self.loadMore
} }
ReactDOM.render( ReactDOM.render(
React.createElement(ReactComponents.Maps, exploreObj), React.createElement(Maps, exploreObj),
document.getElementById('explore') document.getElementById('explore')
) )

View file

@ -30,7 +30,6 @@ import TopicCard from './TopicCard'
import Util from './Util' import Util from './Util'
import Views from './Views' import Views from './Views'
import Visualize from './Visualize' import Visualize from './Visualize'
import ReactComponents from './ReactComponents'
Metamaps.Account = Account Metamaps.Account = Account
Metamaps.Active = Active Metamaps.Active = Active
@ -55,7 +54,6 @@ Metamaps.Mouse = Mouse
Metamaps.Organize = Organize Metamaps.Organize = Organize
Metamaps.PasteInput = PasteInput Metamaps.PasteInput = PasteInput
Metamaps.Realtime = Realtime Metamaps.Realtime = Realtime
Metamaps.ReactComponents = ReactComponents
Metamaps.Router = Router Metamaps.Router = Router
Metamaps.Selected = Selected Metamaps.Selected = Selected
Metamaps.Settings = Settings Metamaps.Settings = Settings

View file

@ -1,9 +1,9 @@
import React, { Component, PropTypes } from 'react' import React, { Component, PropTypes } from 'react'
import { objectWithoutProperties } from '../utils' import _ from 'lodash'
const MapLink = props => { const MapLink = props => {
const { show, text, href, linkClass } = props const { show, text, href, linkClass } = props
const otherProps = objectWithoutProperties(props, ['show', 'text', 'href', 'linkClass']) const otherProps = _.omit(props, ['show', 'text', 'href', 'linkClass'])
if (!show) { if (!show) {
return null return null
} }

View file

@ -1,8 +1,6 @@
// create global references to some utility libraries // create global references
import ReactDOM from 'react-dom'
import _ from 'underscore' import _ from 'underscore'
window.ReactDOM = ReactDOM
window._ = _
import Metamaps from './Metamaps' import Metamaps from './Metamaps'
window._ = _
window.Metamaps = Metamaps window.Metamaps = Metamaps

View file

@ -1,9 +0,0 @@
export const objectWithoutProperties = (obj, keys) => {
const target = {}
for (let i in obj) {
if (keys.indexOf(i) !== -1) continue
if (!Object.prototype.hasOwnProperty.call(obj, i)) continue
target[i] = obj[i]
}
return target
}

View file

@ -18,26 +18,24 @@
}, },
"homepage": "https://github.com/metamaps/metamaps#readme", "homepage": "https://github.com/metamaps/metamaps#readme",
"dependencies": { "dependencies": {
"autolinker": "^0.17.1", "autolinker": "0.17.1",
"babel-cli": "^6.11.4", "babel-cli": "6.11.4",
"babel-loader": "^6.2.4", "babel-loader": "6.2.4",
"babel-plugin-transform-class-properties": "^6.11.5", "babel-plugin-transform-class-properties": "6.11.5",
"babel-preset-es2015": "^6.9.0", "babel-preset-es2015": "6.9.0",
"babel-preset-react": "^6.11.1", "babel-preset-react": "6.11.1",
"backbone": "^1.0.0", "backbone": "1.0.0",
"chai": "^3.5.0",
"jquery": "1.12.1",
"mocha": "^3.0.2",
"mocha-jsdom": "^1.1.0",
"node-uuid": "1.2.0", "node-uuid": "1.2.0",
"react": "^15.3.0", "react": "15.3.0",
"react-dom": "^15.3.0", "react-dom": "15.3.0",
"requirejs": "^2.1.1", "requirejs": "2.1.1",
"socket.io": "0.9.12", "socket.io": "0.9.12",
"underscore": "^1.4.4", "underscore": "1.4.4",
"webpack": "^1.13.1" "webpack": "1.13.1"
}, },
"devDependencies": { "devDependencies": {
"chai": "^3.5.0",
"mocha": "^3.0.2",
"babel-eslint": "^6.1.2", "babel-eslint": "^6.1.2",
"eslint": "^3.5.0", "eslint": "^3.5.0",
"eslint-config-standard": "^6.0.1", "eslint-config-standard": "^6.0.1",