import 'dart:async';

import 'package:zhiying_comm/util/base_bloc.dart';
import 'package:zhiying_comm/zhiying_comm.dart';

class HomePageBloc extends BlocBase {
  List<Map<String, dynamic>> _tabs = List();

  StreamController<List<Map<String, dynamic>>> _tabController =
      StreamController<List<Map<String, dynamic>>>();

  Stream<List<Map<String, dynamic>>> get outData => _tabController.stream;

  @override
  void dispose() {
    _tabController.close();
    _tabController = null;
  }

  void refresh() {
    NetUtil.request('/api/v1/config.json', onCache: (data) {
      _refresh(data);
    }, onSuccess: (data) {
      _refresh(data);
    });
  }

  void _refresh(dynamic data) {
    List list = data;
    _tabs = list.map((item) {
      return Map<String, dynamic>.from(item);
    }).toList();
    _tabController.add(_tabs);
  }
}
