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
class Types::CustomerType < Types::BaseObject | |
implements GraphQL::Relay::Node.interface | |
def self.object_from_id(id, context) | |
CustomerRepository.find(context[:seller], id: id) # or: context[:seller].customers.find_by(id: id) | |
end | |
field :name, String, null: true | |
field :name, Email, null: true | |
# ... |
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
# When run on the following 20 repositories, it found 2082 ||= and it was used as lazy init 64.3% of the time | |
# Those numbers are fuzzy, as there is not certain way to prove if something was used as a lazy init | |
# This script only marks a usage as a lazy init if the variable is being set to a constant, | |
# in which case if it is not a lazy init then the developers have done something weird. | |
# It is also marked as a lazy init if the variable is an instance variable or a class variable (either @var or @@var) | |
# AND the lazy init is used in the top level of a function, AND the function name is contained by the variable or vice versa. | |
# These are almost certain to be lazy initialized because the assumed behaviour is to always call the method instead of the variable, | |
# and other usages would be both weird usage of instance/class variables and/or weird usage of the method naming | |
# This of course, misses a variety of cases but likely does not get any cases that do not lazy initialize. | |
# A better way to profile could be |
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
import React, {useMemo} from 'react' | |
import Animated from 'react-native-reanimated' | |
import {View, Dimensions, StyleSheet} from 'react-native' | |
import FastImage from 'react-native-fast-image' | |
import ConfettiImage from 'assets/images/confetti.png' | |
const NUM_CONFETTI = 100 | |
const COLORS = ['#00e4b2', '#09aec5', '#107ed5'] | |
const CONFETTI_SIZE = 16 |
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
{ | |
"payload": { | |
"op": "c", | |
"ts_ms": 1465491411815, | |
"before": null, | |
"after": { | |
"id": 1, | |
"first_name": "Peyton", | |
"last_name": "Manning", | |
"address1": "18 Willow St", |
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
# Gem | |
module PricingEngine | |
class Engine | |
#... | |
# Calculates the price for variants given the buyer context. | |
# | |
# @param context [Schema::BuyerContext] the buyer context | |
# | |
# @return [Array<PricingEngine::Schema::Price>] An array of prices for the context passed. | |
def calculate_prices_for_variants(context) |
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
module PricingEngine | |
class PricingRepositoryInterface | |
def variants_by_ids(ids) | |
raise NotImplemented | |
end | |
def variants_by_titles(titles) | |
raise NotImplemented | |
end | |
end |
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
# Consumer 1 Logic | |
require 'pricing_engine' | |
module ShopifyCore | |
class PricingRepository < PricingEngine::PricingRepositoryInterface | |
def variants_by_ids(ids) | |
variants = ProductVariant.where(id: ids).select(:title, :price).limit(50) | |
variants.map { |variant| PricingEngine::Schema::Variant.new(title: variant.title, price: variant.price) } | |
end |
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
# Consumer 2 Logic | |
require 'pricing_engine' | |
module StorefrontRenderer | |
class PricingRepository < PricingEngine::PricingRepositoryInterface | |
def variants_by_ids(ids) | |
variants = DataStoreConnection.execute("SELECT title, price FROM variants WHERE id in (?)", ids).limit(50) | |
variants.map { |variant| PricingEngine::Schema::Variant.new(title: variant.title, price: variant.price) } |
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
module PricingEngine | |
class Engine | |
# @param repository [PricingEngine::PricingRepositoryInterface] environment specific functions to | |
# access db and cache data. | |
# | |
# @return [void] | |
def initialize(repository) | |
@repository = repository | |
end |
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
# ----------------------------- Gem ----------------------------- | |
module PricingEngine | |
class PricingRepositoryInterface | |
def variants_by_ids(ids) | |
raise NotImplemented | |
end | |
def variants_by_titles(titles) | |
raise NotImplemented | |
end |
OlderNewer