Skip to content

Commit

Permalink
Use Default trait instead of new() in npm_and_rest example.
Browse files Browse the repository at this point in the history
  • Loading branch information
teymour-aldridge committed Jun 20, 2020
1 parent 964d516 commit fceef03
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 7 deletions.
6 changes: 4 additions & 2 deletions examples/npm_and_rest/src/ccxt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,14 @@ extern "C" {
static ccxt: JsValue;
}

impl CcxtService {
pub fn default() -> Self {
impl Default for CcxtService {
fn default() -> CcxtService {
let lib: &JsValue = &ccxt;
CcxtService(Some(lib))
}
}

impl CcxtService {
pub fn exchanges(&mut self) -> Vec<String> {
let lib = self.0.as_ref().expect("ccxt library object lost");
let v = {
Expand Down
4 changes: 0 additions & 4 deletions examples/npm_and_rest/src/gravatar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,6 @@ pub struct Entry {
pub struct GravatarService {}

impl GravatarService {
pub fn new() -> Self {
Self {}
}

pub fn profile(&mut self, hash: &str, callback: Callback<Result<Profile, Error>>) -> FetchTask {
let url = format!("https://en.gravatar.com/{}.json", hash);
let handler = move |response: Response<Json<Result<Profile, Error>>>| {
Expand Down
2 changes: 1 addition & 1 deletion examples/npm_and_rest/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ impl Component for Model {
fn create(_: Self::Properties, link: ComponentLink<Self>) -> Self {
Model {
link: link.clone(),
gravatar: GravatarService::new(),
gravatar: GravatarService::default(),
ccxt: CcxtService::default(),
callback: link.callback(Msg::GravatarReady),
profile: None,
Expand Down

0 comments on commit fceef03

Please sign in to comment.