Skip to content

Instantly share code, notes, and snippets.

View borlaym's full-sized avatar

Marton Borlay borlaym

  • Budapest, Hungary
View GitHub Profile
@borlaym
borlaym / issue.js
Created October 3, 2019 12:39
The issue
function method(value: { prop?: string }) {
if (value.prop) {
otherMethod();
value.prop.charAt(0);
}
}
@borlaym
borlaym / full-issue.js
Created October 3, 2019 12:44
The full issue
var obj = { prop: "test" };
function otherMethod() {
delete obj.prop;
}
function method(value: { prop?: string }) {
if (value.prop) {
otherMethod();
value.prop.charAt(0);
@borlaym
borlaym / solution.js
Created October 3, 2019 12:47
The solution
function method(value: { prop?: string }) {
const savedProp = value.prop;
if (savedProp) {
otherMethod();
savedProp.charAt(0);
}
}
@borlaym
borlaym / issue.js
Created October 3, 2019 13:07
The issue
function isKinjaVideo(blockNode: BlockNodeJSON): boolean {
return blockNode.type === 'KinjaVideo';
}
export default function getKinjaVideoForPost(post: Post): Array<string> {
const videoNodes = post.body.filter(n => isKinjaVideo(n));
return videoNodes.map(vn => vn.id);
}
@borlaym
borlaym / issue.js
Created October 3, 2019 13:07
The issue
function isKinjaVideo(blockNode: BlockNodeJSON): boolean {
return blockNode.type === 'KinjaVideo';
}
export default function getKinjaVideoForPost(post: Post): Array<string> {
const videoNodes = post.body.filter(n => isKinjaVideo(n));
return videoNodes.map(vn => vn.id);
}
@borlaym
borlaym / solution.js
Created October 3, 2019 13:18
The solution
function getKinjaVideoForPost(post: Post): Array<string> {
const videoNodes = post.body.reduce<Array<KinjaVideoJSON>>((acc, n) => {
if (n.type === 'KinjaVideo') {
return [...acc, n];
}
return acc;
}, []);
return videoNodes.map(vn => vn.id);
}
@borlaym
borlaym / issue.js
Created October 3, 2019 13:45
The issue
get featuredVideoUrl(): ?string {
if (this.featuredMedia && this.featuredMedia.id) {
let videoParams;
switch (this.featuredMedia.type) {
case 'YoutubeVideo':
videoParams = {
id: `youtube-video-${this.featuredMedia.id}`,
start: this.featuredMedia.start
};
break;
@borlaym
borlaym / DeletedEmbedJSON.js
Created October 3, 2019 13:50
DeletedEmbedJSON
export type DeletedEmbedJSON = {
type: 'DeletedEmbed',
originalContent: {type?: string},
deletedReason: ?DeletedReason
};
@borlaym
borlaym / DeletedEmbedJSON.js
Created October 3, 2019 13:50
DeletedEmbedJSON
export type DeletedEmbedJSON = {
type: 'DeletedEmbed',
originalContent: {type?: string},
deletedReason: ?DeletedReason
};
@borlaym
borlaym / DeletedEmbedJSON.js
Created October 3, 2019 14:03
DeletedEmbedJSON Exact
export type DeletedEmbedJSON = {|
type: 'DeletedEmbed',
originalContent: {type?: string},
deletedReason: ?DeletedReason
|};