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
using System.Text; | |
using System.Text.RegularExpressions; | |
public static class StringExtension | |
{ | |
/// <summary> | |
/// Remove unicode character (unicode) of given string | |
/// </summary> | |
/// <param name="input">The input string to remove mark</param> | |
/// <returns>The string without mark</returns> |
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 ProductViewModel { | |
final BehaviorSubject<List<Product>> _products = new BehaviorSubject(); // đây, angular dev quen không : )) | |
Stream<List<Product>> get products$ => _products.stream; // getter | |
Future fetchProductsAsync() async { | |
var products = await loadProductsFromApi(); | |
_products.add(products); // _products.next(products) in rxjs | |
// _products changes thus products$ changes | |
} | |
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 Product extends StatefulWidget { | |
@override | |
_ProductState createState() => _ProductState(); | |
} | |
class _ProductState extends State<Product> { | |
final ProductViewModel _productvm = ProductViewModel(); | |
@override | |
void initState() { |
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
@Component({ | |
selector: "app-product", | |
templateUrl: "./app-product.component.html", | |
styleUrls: ["./app-product.component.scss"] | |
}) | |
export class ProductComponent implements OnInit { | |
products: Product[]; | |
constructor(private readonly productService: ProductService) {} |
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 StreamBuilderObserver extend StatelessWidget { | |
final Function onWaiting; | |
final Function onSuccess; | |
// constructor | |
@override | |
Widget build(BuildContext context) { | |
return StreamBuilder { | |
builder: (BuildContext context, AsyncSnapshot snapshot) { // need to return a Widget | |
if (snapshot.hasData) { |
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
// fake code, it might now work :) | |
public class CacheHelper | |
{ | |
public string GetOrSetConfig(string key, Func<string> factory) | |
{ | |
var cached = CacheProvider.Get<string>(key); | |
if (string.IsNullOrWhiteSpace(cached)) { | |
cached = factory(); | |
} |
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 productService { | |
Future<List<Product>> getProductsAsync() async { | |
var response = await http.get("/api/products"); | |
var products = (response.body as Iterable).map((x) => Product.fromJson(x)).ToList(); | |
return products; | |
} | |
} |
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
public class ProductService | |
{ | |
public async Task<List<Product>> GetProductsAsync() | |
{ | |
var products = await db.Products.Where(...).ToListAsync(); | |
return products. | |
} | |
} |
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
// product.dart | |
// no namespace | |
class Product | |
{ | |
String name; | |
Product(String name) { this.name = name; } | |
// Syntactic sugar for setting prop | |
// Product(this.name) | |
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
// Product.cs | |
namespace AwesomeApp | |
{ | |
public class Product | |
{ | |
public string Name { get; set; } | |
public Product(string name) { this.Name = name; } | |
public void PrintName() { |