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
let displayName = firstName ?? 'Default Name' | |
// it is equivalent to | |
let displayName = firstName !== undefined && firstName !== null ? firsName : 'Default 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
console.log(car?.owner?.account?.firstName) | |
// it is equivalent to | |
console.log( | |
( | |
car !== undefined && car !== null && | |
car.owner !== undefined && car.owner !== null && | |
car.owner.account !== undefined && car.owner.account !== null | |
) ? car.owner.account.firstName : undefined |
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
console.log(user2 !== undefined && user2 !== null ? user2.firstname : undefined); |
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
console.log(user2?.firstname); |
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
const user2 = undefined; | |
// first approach | |
if(user2 !== undefined && user2 !== null) { | |
console.log(user2.firstname); | |
} | |
// second approach | |
console.log(user2 !== undefined && user2 !== null ? user2.firstname : undefined); |
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
const user = { | |
firstName: 'Lorem', | |
lastName: 'Ipsum' | |
}; | |
const user2 = undefined; | |
console.log(user.firstName); | |
// it logs 'Lorem' | |
console.log(user2.firstName); |
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 LoginPresenter : BasePresenter<LoginContract.View>(), LoginContract.Presenter { | |
override fun onViewCreated() { | |
super.onViewCreated() | |
} | |
override fun login(email: String?, password: String?) { | |
} | |
override fun checkEmail(email: String) { |
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
abstract class BasePresenter<V : BaseContract.View> : BaseContract.Presenter<V> { | |
protected var view: V? = null | |
override fun onAttach(view: V) { | |
this.view = view | |
} | |
override fun onViewCreated() { | |
} |
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 LoginFragment : Fragment(), LoginContract.View { | |
private val presenter: LoginPresenter = LoginPresenter() | |
override fun onCreateView( | |
inflater: LayoutInflater, | |
container: ViewGroup?, | |
savedInstanceState: Bundle? | |
): View? { | |
return inflater.inflate(R.layout.fragment_login, container, false) |
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
interface LoginContract { | |
interface View : BaseContract.View { | |
fun showEmailError(error: String?) | |
fun showPasswordError(error: String?) | |
fun disableButton() | |
fun enableButton() | |
} | |
interface Presenter : BaseContract.Presenter<View> { | |
fun login(email: String?, password: String?) |
NewerOlder