Timeline stability improvements
This commit is contained in:
1 parent
beebd497b3
commit
f2d1f71064
2 files changed
+42
-16
No files matched your search
@@ -1,6 +1,6 @@
|
||||
import template from '../../templates/components/timeline.html';
|
||||
|
||||
import {createInstance} from '../../models/TimelinePostInstagram';
|
||||
import {createInstance as createInstagram} from '../../models/TimelinePostInstagram';
|
||||
|
||||
// function personByInstagram(list, instagram){
|
||||
// list = list.filter(function (member) {
|
||||
@@ -43,11 +43,18 @@ import {createInstance} from '../../models/TimelinePostInstagram';
|
||||
// };
|
||||
// }
|
||||
|
||||
const createPost = post => [createInstance]
|
||||
.reduce((post, map) => {
|
||||
let result = map(post);
|
||||
return result ? result : post
|
||||
}, post);
|
||||
const createPost = post => post.type === 'post' ? post : null;
|
||||
const createPosts = items => items
|
||||
.map(createRecord)
|
||||
.filter(i => i);
|
||||
|
||||
function createRecord(post){
|
||||
for (let fn of [createInstagram, createPost]){
|
||||
let result = fn(post);
|
||||
if(result) return result;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
export default function (app) {
|
||||
app.component('timeline', {
|
||||
@@ -74,7 +81,7 @@ export default function (app) {
|
||||
// if (post.type == 'instagram') return toInstagram(post);
|
||||
// else return post;
|
||||
// });
|
||||
feed = feed.map(createPost);
|
||||
feed = createPosts(feed);
|
||||
|
||||
skip += limit;
|
||||
this.feed = this.feed.concat(feed);
|
||||
@@ -86,9 +93,7 @@ export default function (app) {
|
||||
|
||||
io.on('feed', feed => {
|
||||
console.log(feed);
|
||||
|
||||
feed = feed instanceof Array ? feed : [feed];
|
||||
feed = feed.map(createPost);
|
||||
feed = createPosts(feed instanceof Array ? feed : [feed]);
|
||||
|
||||
$timeout(()=> {
|
||||
this.feed = feed.concat(this.feed);
|
||||
|
||||
@@ -28,13 +28,18 @@ export function fromInstagram1(post) {
|
||||
}
|
||||
|
||||
export function fromInstagram2(post) {
|
||||
const caption = safe(post => post.data.caption.text, '');
|
||||
const username = safe(post => post.data.user['username'], '');
|
||||
const userpic = safe(post => post.data.user['profile_picture'], '');
|
||||
const image = safe(post => post.data.images['standard_resolution'].url, '');
|
||||
|
||||
return new TimelinePostInstagram(
|
||||
post.date,
|
||||
post.data.images.standard_resolution.url,
|
||||
image(post),
|
||||
post.data.link,
|
||||
post.data.user.username,
|
||||
post.data.user.profile_picture,
|
||||
post.data.caption.text
|
||||
username(post),
|
||||
userpic(post),
|
||||
caption(post)
|
||||
);
|
||||
}
|
||||
|
||||
@@ -46,7 +51,23 @@ export const types = {
|
||||
export function createInstance(post) {
|
||||
if(post.type in types) {
|
||||
let fn = types[post.type];
|
||||
return fn(post);
|
||||
|
||||
try{
|
||||
return fn(post);
|
||||
}catch(e){
|
||||
return null;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
function safe(fn, defaultValue=null){
|
||||
return function(){
|
||||
try{
|
||||
let i = fn.apply(undefined, arguments);
|
||||
return i ? i : defaultValue;
|
||||
}catch(e){
|
||||
return defaultValue
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user