Some sample code used for a creative coding workshop held at EBAC-SP on Sep 22, 2022.
This file contains hidden or 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
// | |
// # Async Flutter Programming | |
// | |
// 1. Let's use our API class to fetch our users and list them. | |
// 2. Where should we trigger these requests? | |
// 3. Where should we store this state? | |
// | |
// 4. Extra: Let's pretend "UserAvatar" is quite an expensive widget. | |
// How would we refactor our code to make sure we don't re-build all "UserAvatar"s everytime | |
// one of the user score changes? |
This file contains hidden or 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 'package:flutter/material.dart'; | |
void main() { | |
// where the magic happens | |
Stack stack = Stack(title: "Magic "); | |
print(stack._list); | |
stack.push(1); | |
stack.push(2); | |
stack.push(3); | |
print(stack._list); |
This file contains hidden or 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 SingletonValueNoFactory { | |
static SingletonValueNoFactory _instance; | |
final dynamic value; | |
SingletonValueNoFactory._internal(this.value); | |
static SingletonValueNoFactory getInstance(value) { | |
return _instance ??= SingletonValueNoFactory._internal(value); | |
} |
This file contains hidden or 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 { paths } from '../firebase-app' | |
import { FirebaseSync, firebaseSyncConnect } from '../firebase-sync' | |
const User = () => ( | |
<div> | |
<FirebaseSync | |
path={paths.user(props.userId)} /> | |
{user && ( |
This file contains hidden or 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
const { applyAction } = require('../firebase-app'); | |
// create our local database | |
let db = {}; | |
// first user signs up and creates the first post | |
db = applyAction(createUser, createUserPayload, db); | |
db = applyAction(createPost, createPostPayload, db); | |
db = applyAction(updatePost, updatePostPayload, db); |
This file contains hidden or 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
require('firebase-app/rules')({ | |
rules: '/firebase-app/**/*.rules.js', | |
filename: '/database.rules.json', | |
actions: require('./actions/actions'), | |
owners: require('./owners/owners'), | |
paths: require('./paths/paths') | |
}); |
This file contains hidden or 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
// first setup your mocha env as described on targaryen's docs. | |
// ...then: | |
const { paths, actions, getActionUpdates, applyAction } = require('../firebase-app'); | |
describe('firebase-app userflow', () => { | |
it('should be able to update post if is author', () => { | |
const { updates } = getActionUpdates(updatePost, { | |
post: 'post_1', |
This file contains hidden or 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.exports = { | |
__setup__: 'actions', | |
// notice we are defining the rules for a task with this ID. | |
// this has nothing to do with paths. we may access this task payload as shown below. | |
// here we're checking if the post we're updating was created by the authenticated user. | |
updatePost: `newData.child('createdBy').val() == auth.uid` | |
}; |
This file contains hidden or 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.exports = { | |
__setup__: 'owners', | |
// anyone can read our posts logs | |
post: true | |
}; |
NewerOlder