-
Notifications
You must be signed in to change notification settings - Fork 210
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Théo mathieu
committed
Mar 31, 2016
1 parent
4839fb9
commit c2eab55
Showing
6 changed files
with
155 additions
and
55 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import EJSON from "ejson"; | ||
|
||
import Collection from '../Collection'; | ||
import Data from '../Data'; | ||
import setProperties from './setProperties'; | ||
|
||
|
||
EJSON.addType('FS.File', function(value) { | ||
return { | ||
getFileRecord() { | ||
const collection = Data.db['cfs.'+value.collectionName+'.filerecord']; | ||
|
||
const item = collection && collection.get(value._id); | ||
|
||
if(!item) return value; | ||
|
||
return setProperties(value.collectionName, item); | ||
} | ||
}; | ||
}); | ||
|
||
export default function(name) { | ||
|
||
const collectionName = 'cfs.'+name+'.filerecord'; | ||
|
||
|
||
return { | ||
find(selector, options) { | ||
const elems = Collection(collectionName).find(selector, options); | ||
return elems.map(elem=>{ | ||
return setProperties(name, elem); | ||
}); | ||
}, | ||
findOne(selector, options) { | ||
const elem = Collection(collectionName).findOne(selector, options); | ||
return elem && setProperties(name, elem); | ||
}, | ||
insert: Collection(collectionName).insert, | ||
update: Collection(collectionName).update, | ||
remove: Collection(collectionName).remove | ||
}; | ||
} | ||
|
||
|
||
|
||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
'use strict'; | ||
|
||
import React, { | ||
Component, | ||
PropTypes, | ||
View, | ||
Image, | ||
StyleSheet | ||
} from 'react-native'; | ||
|
||
|
||
import Data from '../Data'; | ||
import setProperties from './setProperties'; | ||
|
||
export default class FSCollectionImagesPreloader extends Component { | ||
static propTypes = { | ||
collection: PropTypes.string.isRequired, | ||
selector: PropTypes.oneOfType([ PropTypes.string, PropTypes.object ]) | ||
}; | ||
static defaultProps = { | ||
selector: {} | ||
}; | ||
constructor(props) { | ||
super(props); | ||
this.state = { | ||
items: [] | ||
}; | ||
} | ||
componentWillMount() { | ||
const { collection, selector } = this.props; | ||
|
||
|
||
this.update = results=>{ | ||
this.setState({ | ||
items: results.map(elem=>setProperties(collection, elem)) | ||
}); | ||
}; | ||
|
||
if(!Data.db[collection]) { | ||
Data.db.addCollection(collection) | ||
} | ||
|
||
this.items = Data.db.observe(() => { | ||
return Data.db['cfs.'+collection+'.filerecord'].find(selector); | ||
}); | ||
|
||
this.items.subscribe(this.update); | ||
} | ||
componentWillUnmount() { | ||
this.items.dispose(); | ||
} | ||
render() { | ||
const { items } = this.state; | ||
|
||
return ( | ||
<View style={styles.hidden}> | ||
{items && items.map(item=>{ | ||
return ( | ||
<Image style={styles.hidden} key={item._id} onLoadEnd={()=>console.log('LOADED IMAGE')} source={{uri: item.url()}} /> | ||
); | ||
})} | ||
</View> | ||
); | ||
} | ||
} | ||
|
||
const styles = StyleSheet.create({ | ||
hidden: { | ||
width: 1, | ||
height: 1, | ||
position: 'absolute', | ||
top: -100000, | ||
left: -10000, | ||
opacity: 0 | ||
} | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters